curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

RE: CURLOPT_XOAUTH2_BEARER use?

From: Matthew Bobowski via curl-library <curl-library_at_lists.haxx.se>
Date: Tue, 21 Feb 2023 03:01:53 +0000

Gavin,

Example of usage:

#include <curl/curl.h>
#include <string>
#include "curl/curlcategory.hpp"

using std::string;

Bearer::Bearer(string token) :
    m_token(token)
{}

const char* Bearer::get_Token() const noexcept
{
    return m_token.c_str();
}

void Bearer::Authenticate(CURL* pCurl) const
{
    CURLcode c = CURLE_OK;

    std::cerr << "Warning: memory set with CURLOPT_XOAUTH2_BEARER is known to leak." << std::endl;

    // This libcurl code works, but leaks the bearer token.
    // https://github.com/curl/curl/issues/8841
    c = curl_easy_setopt(pCurl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);
    if (CURLE_OK != c)
        throw std::system_error(c, curl_category());
    c = curl_easy_setopt(pCurl, CURLOPT_XOAUTH2_BEARER, getToken());
    if (CURLE_OK != c)
        throw std::system_error(c, curl_category());
}

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Gavin Henry via curl-library<mailto:curl-library_at_lists.haxx.se>
Sent: Monday, February 20, 2023 6:46 PM
To: libcurl development<mailto:curl-library_at_lists.haxx.se>
Cc: Gavin Henry<mailto:ghenry_at_sentrypeer.org>
Subject: Re: CURLOPT_XOAUTH2_BEARER use?


In the absence of your code listing and lack of additional info, I can only try to guess...

- Protocol is http(s)

. You do not set CURLOPT_HTTPAUTH (https://curl.se/libcurl/c/CURLOPT_HTTPAUTH.html). This is probably what you need.
Thanks! I did my first version today, but this will simplify things :)

Gavin.



-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2023-02-21