oauth2.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  * RFC6749 OAuth 2.0 Authorization Framework
00022  *
00023  ***************************************************************************/
00024 
00025 #include "curl_setup.h"
00026 
00027 #include <curl/curl.h>
00028 #include "urldata.h"
00029 
00030 #include "vauth/vauth.h"
00031 #include "curl_base64.h"
00032 #include "warnless.h"
00033 #include "curl_printf.h"
00034 
00035 /* The last #include files should be: */
00036 #include "curl_memory.h"
00037 #include "memdebug.h"
00038 
00039 /*
00040  * Curl_auth_create_oauth_bearer_message()
00041  *
00042  * This is used to generate an already encoded OAuth 2.0 message ready for
00043  * sending to the recipient.
00044  *
00045  * Parameters:
00046  *
00047  * data[in]         - The session handle.
00048  * user[in]         - The user name.
00049  * host[in]         - The host name(for OAUTHBEARER).
00050  * port[in]         - The port(for OAUTHBEARER when not Port 80).
00051  * bearer[in]       - The bearer token.
00052  * outptr[in / out] - The address where a pointer to newly allocated memory
00053  *                    holding the result will be stored upon completion.
00054  * outlen[out]      - The length of the output message.
00055  *
00056  * Returns CURLE_OK on success.
00057  */
00058 CURLcode Curl_auth_create_oauth_bearer_message(struct Curl_easy *data,
00059                                                const char *user,
00060                                                const char *host,
00061                                                const long port,
00062                                                const char *bearer,
00063                                                char **outptr, size_t *outlen)
00064 {
00065   CURLcode result = CURLE_OK;
00066   char *oauth = NULL;
00067 
00068   /* Generate the message */
00069   if(host == NULL && (port == 0 || port == 80))
00070     oauth = aprintf("user=%s\1auth=Bearer %s\1\1", user, bearer);
00071   else if(port == 0 || port == 80)
00072     oauth = aprintf("user=%s\1host=%s\1auth=Bearer %s\1\1", user, host,
00073                     bearer);
00074   else
00075     oauth = aprintf("user=%s\1host=%s\1port=%ld\1auth=Bearer %s\1\1", user,
00076                     host, port, bearer);
00077   if(!oauth)
00078     return CURLE_OUT_OF_MEMORY;
00079 
00080   /* Base64 encode the reply */
00081   result = Curl_base64_encode(data, oauth, strlen(oauth), outptr, outlen);
00082 
00083   free(oauth);
00084 
00085   return result;
00086 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05