CURLOPT_XOAUTH2_BEARER(3)

πŸ’… CURLOPT_XOAUTH2_BEARER(3) πŸ’…

okay so bestie, this is a libcurl page from the Library Functions Manual, and it's all about the OAuth 2.0 access token option. pull up a chair, we're gonna make it make sense. ✨


🌸 NAME 🌸

CURLOPT_XOAUTH2_BEARER β€” OAuth 2.0 access token


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XOAUTH2_BEARER, char *token);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so you pass a char pointer as the parameter, and that pointer should point to the null-terminated OAuth 2.0 Bearer Access Token. it's for use with HTTP, IMAP, LDAP, POP3 and SMTP servers that support the OAuth 2.0 Authorization Framework. πŸ’…

note, bestie: for IMAP, LDAP, POP3 and SMTP, the username used to generate the Bearer Token should be supplied via the CURLOPT_USERNAME(3) option. iykyk. 🫢

the application does not have to keep the string around after setting this option. so no need to clutch it forever. 😌

using this option multiple times makes the last set string override the previous ones. set it to NULL to disable its use again. fr fr. πŸ”₯


πŸŽ€ DEFAULT πŸŽ€

NULL β€” that's the default, no token, no problem. periodt. πŸ’…


🌈 PROTOCOLS 🌈

This functionality affects http, imap, ldap, pop3 and smtp. that's the whole vibe check, no gatekeeping. ✨


πŸ“ EXAMPLE πŸ“

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "pop3://example.com/");
    curl_easy_setopt(curl, CURLOPT_XOAUTH2_BEARER, "1ab9cb22bf269a7");
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

🧚 HISTORY 🧚

Support for OpenLDAP added in 7.82.0. slay, OpenLDAP got her moment. πŸ‘‘


⭐ AVAILABILITY ⭐

Added in curl 7.33.0. she's been around, and she's iconic. πŸ’–


πŸ”₯ RETURN VALUE πŸ”₯

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3). so yeah, zero is the good vibe, non-zero is your cue to go read the errors page. 😭


🫢 SEE ALSO 🫢

go read these next, bestie. they're literally right there. πŸ’œ


xoxo, source/version libcurl πŸ’– β€” dated 2026-10-12, and yes bestie this is the CURLOPT_XOAUTH2_BEARER(3) page. mwah! πŸŽ€

πŸ“¦ where this page comes from