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


Re: CURLOPT_XOAUTH2_BEARER use?

2023-02-20 Thread Gavin Henry via curl-library
>
> 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


Re: CURLOPT_XOAUTH2_BEARER use?

2023-02-20 Thread Patrick Monnerat via curl-library


On 2/20/23 15:25, Gavin Henry via curl-library wrote:
If I do the usual, then all is good:  > > headers = curl_slist_append(headers, "Authorization: Bearer > 

xx"); > Yes, that just forces it!

I must be missing setting another curl_easy_setopt...  >


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.
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html


Re: CURLOPT_XOAUTH2_BEARER use?

2023-02-20 Thread Gavin Henry via curl-library
If I do the usual, then all is good:

headers = curl_slist_append(headers, "Authorization: Bearer xx");

I must be missing setting another curl_easy_setopt...


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


Re: CURLOPT_XOAUTH2_BEARER use?

2023-02-20 Thread Gavin Henry via curl-library
> The code search seems to be a beta github feature: I do not have access
to it and as all betas, it may still be incomplete.
>
> Running on my local clone, I get:
>
> $ find lib include -type f | xargs grep -F CURLOPT_XOAUTH2_BEARER
> lib/easyoptions.c:  {"XOAUTH2_BEARER", CURLOPT_XOAUTH2_BEARER,
CURLOT_STRING, 0},
> lib/setopt.c:  case CURLOPT_XOAUTH2_BEARER:
> include/curl/typecheck-gcc.h:   (option) == CURLOPT_XOAUTH2_BEARER ||
 \
> include/curl/curl.h:  CURLOPT(CURLOPT_XOAUTH2_BEARER,
CURLOPTTYPE_STRINGPOINT, 220),
>
>
> Thus if you include the regular libcurl header file, it'll get defined.
>
> Note that github search may have missed the definition because it's done
via a macro... only a supposition, of course!

Thanks Patrick. Yep, there's no issue with it being defined:

It's the usage of it I think is my problem? I'm not seeing a Authorization
Bearer header getting added at all.


--
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 Patrick Monnerat via curl-library


On 2/20/23 12:57, Gavin Henry via curl-library wrote:

Hi all,

I'm reading https://curl.se/libcurl/c/CURLOPT_XOAUTH2_BEARER.html but 
can't seem to see the header at all or find any code at 
https://github.com/curl/curl/search?q=CURLOPT_XOAUTH2_BEARER


The code search seems to be a beta github feature: I do not have access 
to it and as all betas, it may still be incomplete.


Running on my local clone, I get:

$ find lib include -type f | xargs grep -F CURLOPT_XOAUTH2_BEARER
lib/easyoptions.c:  {"XOAUTH2_BEARER", CURLOPT_XOAUTH2_BEARER, 
CURLOT_STRING, 0},

lib/setopt.c:  case CURLOPT_XOAUTH2_BEARER:
include/curl/typecheck-gcc.h:   (option) == CURLOPT_XOAUTH2_BEARER 
||  \
include/curl/curl.h:  CURLOPT(CURLOPT_XOAUTH2_BEARER, 
CURLOPTTYPE_STRINGPOINT, 220),



Thus if you include the regular libcurl header file, it'll get defined.

Note that github search may have missed the definition because it's done 
via a macro... only a supposition, of course!
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html


CURLOPT_XOAUTH2_BEARER use?

2023-02-20 Thread Gavin Henry via curl-library
Hi all,

I'm reading https://curl.se/libcurl/c/CURLOPT_XOAUTH2_BEARER.html but can't
seem to see the header at all or find any code at
https://github.com/curl/curl/search?q=CURLOPT_XOAUTH2_BEARER

For example?


res = curl_easy_setopt(
   curl, CURLOPT_XOAUTH2_BEARER,
  "zxczx");
   if (res != CURLE_OK) {
  fprintf(stderr, "curl_easy_setopt() failed: %s\n",
 curl_easy_strerror(res));

  free(json_string);
  http_cleanup_curl(curl, headers);

  return EXIT_FAILURE;
   }
}

res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
if (res != CURLE_OK) {
   fprintf(stderr, "curl_easy_setopt() failed: %s\n",
  curl_easy_strerror(res));

   free(json_string);
   http_cleanup_curl(curl, headers);

   return EXIT_FAILURE;
}

// Send the json :-)
res = curl_easy_perform(curl);


What am I missing? Is it better to just add the header by hand?

Thanks.


--
Kind Regards,

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