![]() |
C++ Rest SDK
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
|
OAuth 2.0 configuration. More...
#include <oauth2.h>
Public Member Functions | |
oauth2_config (utility::string_t client_key, utility::string_t client_secret, utility::string_t auth_endpoint, utility::string_t token_endpoint, utility::string_t redirect_uri, utility::string_t scope=utility::string_t()) | |
_ASYNCRTIMP utility::string_t | build_authorization_uri (bool generate_state) |
Builds an authorization URI to be loaded in the web browser/view. The URI is built with auth_endpoint() as basis. The implicit_grant() affects the built URI by selecting either authorization code or implicit grant flow. You can set generate_state to generate a new random state string. More... | |
_ASYNCRTIMP pplx::task< void > | token_from_redirected_uri (const web::http::uri &redirected_uri) |
Fetch an access token (and possibly a refresh token) based on redirected URI. Behavior depends on the implicit_grant() setting. If implicit_grant() is false, the URI is parsed for 'code' parameter, and then token_from_code() is called with this code. See: http://tools.ietf.org/html/rfc6749#section-4.1 Otherwise, redirect URI fragment part is parsed for 'access_token' parameter, which directly contains the token(s). See: http://tools.ietf.org/html/rfc6749#section-4.2 In both cases, the 'state' parameter is parsed and is verified to match state(). More... | |
pplx::task< void > | token_from_code (utility::string_t authorization_code) |
Fetches an access token (and possibly a refresh token) from the token endpoint. The task creates an HTTP request to the token_endpoint() which exchanges the authorization code for the token(s). This also sets the refresh token if one was returned. See: http://tools.ietf.org/html/rfc6749#section-4.1.3 More... | |
pplx::task< void > | token_from_refresh () |
Fetches a new access token (and possibly a new refresh token) using the refresh token. The task creates a HTTP request to the token_endpoint(). If successful, resulting access token is set as active via set_token(). See: http://tools.ietf.org/html/rfc6749#section-6 This also sets a new refresh token if one was returned. More... | |
bool | is_enabled () const |
Returns enabled state of the configuration. The oauth2_handler will perform OAuth 2.0 authentication only if this method returns true. Return value is true if access token is valid (=fetched or manually set). More... | |
const utility::string_t & | client_key () const |
Get client key. More... | |
void | set_client_key (utility::string_t client_key) |
Set client key. More... | |
const utility::string_t & | client_secret () const |
Get client secret. More... | |
void | set_client_secret (utility::string_t client_secret) |
Set client secret. More... | |
const utility::string_t & | auth_endpoint () const |
Get authorization endpoint URI string. More... | |
void | set_auth_endpoint (utility::string_t auth_endpoint) |
Set authorization endpoint URI string. More... | |
const utility::string_t & | token_endpoint () const |
Get token endpoint URI string. More... | |
void | set_token_endpoint (utility::string_t token_endpoint) |
Set token endpoint URI string. More... | |
const utility::string_t & | redirect_uri () const |
Get redirect URI string. More... | |
void | set_redirect_uri (utility::string_t redirect_uri) |
Set redirect URI string. More... | |
const utility::string_t & | scope () const |
Get scope used in authorization for token. More... | |
void | set_scope (utility::string_t scope) |
Set scope for authorization for token. More... | |
const utility::string_t & | state () |
Get client state string used in authorization. More... | |
void | set_state (utility::string_t state) |
Set client state string for authorization for token. The state string is used in authorization for security reasons (to uniquely identify authorization sessions). If desired, suitably secure state string can be automatically generated by build_authorization_uri(). A good state string consist of 30 or more random alphanumeric characters. More... | |
const oauth2_token & | token () const |
Get token. More... | |
void | set_token (oauth2_token token) |
Set token. More... | |
bool | implicit_grant () const |
Get implicit grant setting for authorization. More... | |
void | set_implicit_grant (bool implicit_grant) |
Set implicit grant setting for authorization. False means authorization code grant is used for authorization. True means implicit grant is used. Default: False. More... | |
bool | bearer_auth () const |
Get bearer token authentication setting. More... | |
void | set_bearer_auth (bool bearer_auth) |
Set bearer token authentication setting. This must be selected based on what the service accepts. True means access token is passed in the request header. (http://tools.ietf.org/html/rfc6750#section-2.1) False means access token in passed in the query parameters. (http://tools.ietf.org/html/rfc6750#section-2.3) Default: True. More... | |
bool | http_basic_auth () const |
Get HTTP Basic authentication setting for token endpoint. More... | |
void | set_http_basic_auth (bool http_basic_auth) |
Set HTTP Basic authentication setting for token endpoint. This setting must be selected based on what the service accepts. True means HTTP Basic authentication is used for the token endpoint. False means client key & secret are passed in the HTTP request body. Default: True. More... | |
const utility::string_t & | access_token_key () const |
Get access token key. More... | |
void | set_access_token_key (utility::string_t access_token_key) |
Set access token key. If the service requires a "non-standard" key you must set it here. Default: "access_token". More... | |
const web_proxy & | proxy () const |
Get the web proxy object More... | |
void | set_proxy (const web_proxy &proxy) |
Set the web proxy object that will be used by token_from_code and token_from_refresh More... | |
Friends | |
class | web::http::client::http_client_config |
class | web::http::oauth2::details::oauth2_handler |
OAuth 2.0 configuration.
Encapsulates functionality for:
Performing OAuth 2.0 authorization:
Usage for issuing authenticated requests:
|
inline |
Get access token key.
|
inline |
Get authorization endpoint URI string.
|
inline |
Get bearer token authentication setting.
_ASYNCRTIMP utility::string_t web::http::oauth2::experimental::oauth2_config::build_authorization_uri | ( | bool | generate_state | ) |
Builds an authorization URI to be loaded in the web browser/view. The URI is built with auth_endpoint() as basis. The implicit_grant() affects the built URI by selecting either authorization code or implicit grant flow. You can set generate_state to generate a new random state string.
generate_state | If true, a new random state() string is generated which replaces the current state(). If false, state() is unchanged and used as-is. |
|
inline |
Get client key.
|
inline |
Get client secret.
|
inline |
Get HTTP Basic authentication setting for token endpoint.
|
inline |
Get implicit grant setting for authorization.
|
inline |
Returns enabled state of the configuration. The oauth2_handler will perform OAuth 2.0 authentication only if this method returns true. Return value is true if access token is valid (=fetched or manually set).
|
inline |
Get the web proxy object
|
inline |
Get redirect URI string.
|
inline |
Get scope used in authorization for token.
|
inline |
Set access token key. If the service requires a "non-standard" key you must set it here. Default: "access_token".
|
inline |
Set authorization endpoint URI string.
auth_endpoint | Authorization endpoint URI string to set. |
|
inline |
Set bearer token authentication setting. This must be selected based on what the service accepts. True means access token is passed in the request header. (http://tools.ietf.org/html/rfc6750#section-2.1) False means access token in passed in the query parameters. (http://tools.ietf.org/html/rfc6750#section-2.3) Default: True.
bearer_auth | The bearer token authentication setting to set. |
|
inline |
Set client key.
client_key | Client key string to set. |
|
inline |
Set client secret.
client_secret | Client secret string to set. |
|
inline |
Set HTTP Basic authentication setting for token endpoint. This setting must be selected based on what the service accepts. True means HTTP Basic authentication is used for the token endpoint. False means client key & secret are passed in the HTTP request body. Default: True.
http_basic_auth | The HTTP Basic authentication setting to set. |
|
inline |
Set implicit grant setting for authorization. False means authorization code grant is used for authorization. True means implicit grant is used. Default: False.
implicit_grant | The implicit grant setting to set. |
|
inline |
Set the web proxy object that will be used by token_from_code and token_from_refresh
proxy | A reference to the web proxy object. |
|
inline |
Set redirect URI string.
redirect_uri | Redirect URI string to set. |
|
inline |
Set scope for authorization for token.
scope | Scope string for authorization for token. |
|
inline |
Set client state string for authorization for token. The state string is used in authorization for security reasons (to uniquely identify authorization sessions). If desired, suitably secure state string can be automatically generated by build_authorization_uri(). A good state string consist of 30 or more random alphanumeric characters.
state | Client authorization state string to set. |
|
inline |
Set token.
token | Token to set. |
|
inline |
Set token endpoint URI string.
token_endpoint | Token endpoint URI string to set. |
|
inline |
Get client state string used in authorization.
|
inline |
Get token.
|
inline |
Get token endpoint URI string.
|
inline |
Fetches an access token (and possibly a refresh token) from the token endpoint. The task creates an HTTP request to the token_endpoint() which exchanges the authorization code for the token(s). This also sets the refresh token if one was returned. See: http://tools.ietf.org/html/rfc6749#section-4.1.3
authorization_code | Code received via redirect upon successful authorization. |
_ASYNCRTIMP pplx::task<void> web::http::oauth2::experimental::oauth2_config::token_from_redirected_uri | ( | const web::http::uri & | redirected_uri | ) |
Fetch an access token (and possibly a refresh token) based on redirected URI. Behavior depends on the implicit_grant() setting. If implicit_grant() is false, the URI is parsed for 'code' parameter, and then token_from_code() is called with this code. See: http://tools.ietf.org/html/rfc6749#section-4.1 Otherwise, redirect URI fragment part is parsed for 'access_token' parameter, which directly contains the token(s). See: http://tools.ietf.org/html/rfc6749#section-4.2 In both cases, the 'state' parameter is parsed and is verified to match state().
redirected_uri | The URI where web browser/view was redirected after resource owner's authorization. |
|
inline |
Fetches a new access token (and possibly a new refresh token) using the refresh token. The task creates a HTTP request to the token_endpoint(). If successful, resulting access token is set as active via set_token(). See: http://tools.ietf.org/html/rfc6749#section-6 This also sets a new refresh token if one was returned.