1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * SPDX-License-Identifier: curl
23 * RFC6749 OAuth 2.0 Authorization Framework
25 ***************************************************************************/
27 #include "curl_setup.h"
29 #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \
30 !defined(CURL_DISABLE_POP3)
32 #include <curl/curl.h>
35 #include "vauth/vauth.h"
37 #include "curl_printf.h"
39 /* The last #include files should be: */
40 #include "curl_memory.h"
44 * Curl_auth_create_oauth_bearer_message()
46 * This is used to generate an OAuth 2.0 message ready for sending to the
51 * user[in] - The user name.
52 * host[in] - The host name.
53 * port[in] - The port(when not Port 80).
54 * bearer[in] - The bearer token.
55 * out[out] - The result storage.
57 * Returns CURLE_OK on success.
59 CURLcode Curl_auth_create_oauth_bearer_message(const char *user,
67 /* Generate the message */
68 if(port == 0 || port == 80)
69 oauth = aprintf("n,a=%s,\1host=%s\1auth=Bearer %s\1\1", user, host,
72 oauth = aprintf("n,a=%s,\1host=%s\1port=%ld\1auth=Bearer %s\1\1", user,
75 return CURLE_OUT_OF_MEMORY;
77 Curl_bufref_set(out, oauth, strlen(oauth), curl_free);
82 * Curl_auth_create_xoauth_bearer_message()
84 * This is used to generate a XOAuth 2.0 message ready for * sending to the
89 * user[in] - The user name.
90 * bearer[in] - The bearer token.
91 * out[out] - The result storage.
93 * Returns CURLE_OK on success.
95 CURLcode Curl_auth_create_xoauth_bearer_message(const char *user,
99 /* Generate the message */
100 char *xoauth = aprintf("user=%s\1auth=Bearer %s\1\1", user, bearer);
102 return CURLE_OUT_OF_MEMORY;
104 Curl_bufref_set(out, xoauth, strlen(xoauth), curl_free);
107 #endif /* disabled, no users */