aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2015-09-05 17:08:54 +0100
committerSteve Holme <steve_holme@hotmail.com>2015-11-11 22:26:21 +0000
commitdcf5b614ca2ceaa3cf6ee763d73d5ea57f8d3cda (patch)
tree8ee4033d19764a52e38e8483ed777a7a2c9ec4e9 /lib
parent6479f5a076c2a8cddf1da3bb770391f819bf469a (diff)
oauth2: Introduced support for host and port details
Added support to the OAuth 2.0 message function for host and port, in order to accommodate the official OAUTHBEARER SASL mechanism which is to be added shortly.
Diffstat (limited to 'lib')
-rw-r--r--lib/curl_sasl.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/curl_sasl.c b/lib/curl_sasl.c
index 49a51baf9..a0c989915 100644
--- a/lib/curl_sasl.c
+++ b/lib/curl_sasl.c
@@ -1163,6 +1163,8 @@ void Curl_sasl_ntlm_cleanup(struct ntlmdata *ntlm)
*
* data [in] - The session handle.
* user [in] - The user name.
+ * host [in] - The host name (for OAUTHBEARER).
+ * port [in] - The port (for OAUTHBEARER when not Port 80).
* bearer [in] - The bearer token.
* outptr [in/out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
@@ -1172,21 +1174,30 @@ void Curl_sasl_ntlm_cleanup(struct ntlmdata *ntlm)
*/
static CURLcode sasl_create_oauth_bearer_message(struct SessionHandle *data,
const char *user,
+ const char *host,
+ const long port,
const char *bearer,
char **outptr, size_t *outlen)
{
CURLcode result = CURLE_OK;
- char *xoauth = NULL;
+ char *oauth = NULL;
/* Generate the message */
- xoauth = aprintf("user=%s\1auth=Bearer %s\1\1", user, bearer);
- if(!xoauth)
+ if(host == NULL && (port == 0 || port == 80))
+ oauth = aprintf("user=%s\1auth=Bearer %s\1\1", user, bearer);
+ else if(port == 0 || port == 80)
+ oauth = aprintf("user=%s\1host=%s\1auth=Bearer %s\1\1", user, host,
+ bearer);
+ else
+ oauth = aprintf("user=%s\1host=%s\1port=%ld\1auth=Bearer %s\1\1", user,
+ host, port, bearer);
+ if(!oauth)
return CURLE_OUT_OF_MEMORY;
/* Base64 encode the reply */
- result = Curl_base64_encode(data, xoauth, strlen(xoauth), outptr, outlen);
+ result = Curl_base64_encode(data, oauth, strlen(oauth), outptr, outlen);
- free(xoauth);
+ free(oauth);
return result;
}
@@ -1451,6 +1462,7 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
if(force_ir || data->set.sasl_ir)
result = sasl_create_oauth_bearer_message(data, conn->user,
+ NULL, 0,
conn->oauth_bearer,
&resp, &len);
}
@@ -1630,6 +1642,7 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
case SASL_XOAUTH2:
/* Create the authorisation message */
result = sasl_create_oauth_bearer_message(data, conn->user,
+ NULL, 0,
conn->oauth_bearer, &resp, &len);
break;
case SASL_CANCEL: