Re: CURLOPT_XOAUTH2_BEARER use?

2023-02-21 Thread Gavin Henry via curl-library
>
> 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());
>
> }
>

Thanks all for your kind replies and thanks for this Matthew. The memory
leak comment above is a bit worrying? Is that a known bug upstream?

I ended up doing this:

https://github.com/SentryPeer/SentryPeer/blob/main/src/json_logger.c#L175

after requesting my token:

https://github.com/SentryPeer/SentryPeer/blob/main/src/json_logger.c#L67

Hopefully get change to refactor it and delete some code :-)

-- 
Kind Regards,

Gavin Henry.
https://sentrypeer.org
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html


Re: CURLOPT_XOAUTH2_BEARER use?

2023-02-20 Thread Dan Fandrich via curl-library
On Tue, Feb 21, 2023 at 03:19:12AM +, Matthew Bobowski wrote:
> No cast is necessary.
> 
> #define CURLAUTH_BEARER   (((unsigned long)1)<<6)

Ah, good. Many of the other contants (like CURLSSH_AUTH_* and CURLFTPAUTH_*)
*do* need that cast.
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html


RE: CURLOPT_XOAUTH2_BEARER use?

2023-02-20 Thread Matthew Bobowski via curl-library
No cast is necessary.

#define CURLAUTH_BEARER   (((unsigned long)1)<<6)


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

From: Dan Fandrich via curl-library<mailto:curl-library@lists.haxx.se>
Sent: Monday, February 20, 2023 10:16 PM
To: curl-library@lists.haxx.se<mailto:curl-library@lists.haxx.se>
Cc: Dan Fandrich<mailto:d...@coneharvesters.com>
Subject: Re: CURLOPT_XOAUTH2_BEARER use?

On Tue, Feb 21, 2023 at 03:01:53AM +, Matthew Bobowski via curl-library 
wrote:
> c = curl_easy_setopt(pCurl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);

Don't forget to cast this to a long; this makes a difference in some
environments.

Dan
--
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html

-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html


Re: CURLOPT_XOAUTH2_BEARER use?

2023-02-20 Thread Dan Fandrich via curl-library
On Tue, Feb 21, 2023 at 03:01:53AM +, Matthew Bobowski via curl-library 
wrote:
> c = curl_easy_setopt(pCurl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);

Don't forget to cast this to a long; this makes a difference in some
environments.

Dan
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html


RE: CURLOPT_XOAUTH2_BEARER use?

2023-02-20 Thread Matthew Bobowski via curl-library
Gavin,

Example of usage:

#include 
#include 
#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@lists.haxx.se>
Sent: Monday, February 20, 2023 6:46 PM
To: libcurl development<mailto:curl-library@lists.haxx.se>
Cc: Gavin Henry<mailto:ghe...@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