aboutsummaryrefslogtreecommitdiff
path: root/lib/curl_sasl.c
diff options
context:
space:
mode:
authorKyle L. Huff <kyle.huff@curetheitch.com>2013-08-25 13:17:01 -0400
committerSteve Holme <steve_holme@hotmail.com>2013-08-25 22:02:38 +0100
commit19a05c908f7d8be82de6f69f533317d8a0db49dd (patch)
treedcc996b81a8153791ac78c64d24363a85a02fa53 /lib/curl_sasl.c
parentbb5529331334e1e1c79ff3320220bba12fc8457d (diff)
sasl: added basic SASL XOAUTH2 support
Added the ability to generated a base64 encoded XOAUTH2 token containing: "user=<username>^Aauth=Bearer <bearer token>^A^A" as per RFC6749 "OAuth 2.0 Authorization Framework".
Diffstat (limited to 'lib/curl_sasl.c')
-rw-r--r--lib/curl_sasl.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/curl_sasl.c b/lib/curl_sasl.c
index 924be4bbc..b3ffc6615 100644
--- a/lib/curl_sasl.c
+++ b/lib/curl_sasl.c
@@ -22,6 +22,7 @@
* RFC2831 DIGEST-MD5 authentication
* RFC4422 Simple Authentication and Security Layer (SASL)
* RFC4616 PLAIN authentication
+ * RFC6749 OAuth 2.0 Authorization Framework
*
***************************************************************************/
@@ -478,6 +479,40 @@ CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
#endif /* USE_NTLM */
/*
+ * Curl_sasl_create_xoauth2_message()
+ *
+ * This is used to generate an already encoded XOAUTH2 message ready
+ * for sending to the recipient.
+ *
+ * Parameters:
+ *
+ * data [in] - The session handle.
+ * user [in] - The user name.
+ * bearer [in] - The XOAUTH Bearer token.
+ * outptr [in/out] - The address where a pointer to newly allocated memory
+ * holding the result will be stored upon completion.
+ * outlen [out] - The length of the output message.
+ *
+ * Returns CURLE_OK on success.
+ */
+CURLcode Curl_sasl_create_xoauth2_message(struct SessionHandle *data,
+ const char *user,
+ const char *bearer,
+ char **outptr, size_t *outlen)
+{
+ char *xoauth;
+
+ xoauth = aprintf("user=%s\1auth=Bearer %s\1\1", user, bearer);
+
+ if(!xoauth)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* Base64 encode the reply */
+ return Curl_base64_encode(data, xoauth, strlen(xoauth), outptr,
+ outlen);
+}
+
+/*
* Curl_sasl_cleanup()
*
* This is used to cleanup any libraries or curl modules used by the sasl