]> granicus.if.org Git - curl/commitdiff
oauth2: Introduced support for host and port details
authorSteve Holme <steve_holme@hotmail.com>
Sat, 5 Sep 2015 16:08:54 +0000 (17:08 +0100)
committerSteve Holme <steve_holme@hotmail.com>
Wed, 11 Nov 2015 22:26:21 +0000 (22:26 +0000)
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.

lib/curl_sasl.c

index 49a51baf9d8e239cfa2fd61d443e1800d882cbdd..a0c9899152ba0eaaad548cb0bf299d3281186c66 100644 (file)
@@ -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: