Google APIs Client Library for C++
|
Specifies an OAuth 2.0 Credential. More...
#include "client/auth/oauth2_authorization.h"
Public Member Functions | |
OAuth2Credential () | |
Constructs an empty credential. | |
~OAuth2Credential () | |
Standard destructor. | |
void | Clear () |
Clears all the values in the credential but does not revoke any tokens. | |
void | set_flow (OAuth2AuthorizationFlow *flow) |
Binds a flow to this instance so that it can support Refresh(). | |
OAuth2AuthorizationFlow * | flow () const |
Returns the flow currently bound. | |
void | set_access_token (const StringPiece &access_token) |
Sets the access token. | |
void | set_refresh_token (const StringPiece &refresh_token) |
Sets the refresh token. | |
const ThreadsafeString & | access_token () const |
Returns the access token. | |
ThreadsafeString * | mutable_access_token () |
Returns a modifiable access token. | |
const ThreadsafeString & | refresh_token () const |
Returns the refresh token. | |
ThreadsafeString * | mutable_refresh_token () |
Returns a modifiable access token. | |
int64 | expiration_timestamp_secs () const |
Returns the timestamp (in epoch seconds) when the access token will expire. | |
void | set_expiration_timestamp_secs (int64 secs) |
Sets the timestamp (in epoch seconds) when the access token will expire. | |
virtual util::Status | Load (DataReader *reader) |
Resets the credential from the JSON data in the reader. | |
virtual util::Status | Update (DataReader *reader) |
Updates the credential attributes from the JSON data in the reader. | |
virtual DataReader * | MakeDataReader () const |
Serializes the credential as a JSON stream. | |
virtual const StringPiece | type () const |
Identifies this as an kOAuth2Type credential. | |
virtual util::Status | AuthorizeRequest (HttpRequest *request) |
Adds the OAuth 2.9 Authorization Bearer header to the request. | |
util::Status | UpdateFromString (const StringPiece &json) |
Updates the credential from a JSON string. | |
const string & | user_id () const |
Returns the user ID associated with this credential, if known. | |
bool | user_id_verified () const |
Returns true if the user_id has been verified to be the actual user id that authorized access. | |
void | set_user_id (const StringPiece &user_id, bool verified) |
Set the user_id for the credential. | |
virtual util::Status | Refresh () |
Attempts to refresh the credential. | |
Static Public Attributes | |
static const StringPiece | kOAuth2CredentialType |
The AuthorizationCredential type identfying OAuth 2.0 credentials. |
Specifies an OAuth 2.0 Credential.
The purpose of a credential is to carry the available access and refresh tokens used to authorize HTTP requests.
The easiest way to manage credentials is using OAuth2AuthorizationFlow::RefreshCredentialWithOptions(), which lets you treat the credential as an opaque type and not worry about any of its attributes or other methods to manage them.
However sometimes you may need to manipulate the credentials directly if you are using non-standard storage techniques.
OAuth2Credential | ( | ) |
Constructs an empty credential.
~OAuth2Credential | ( | ) |
Standard destructor.
const ThreadsafeString& access_token | ( | ) | const [inline] |
Returns the access token.
The access token might no longer be valid.
virtual util::Status AuthorizeRequest | ( | HttpRequest * | request | ) | [virtual] |
Adds the OAuth 2.9 Authorization Bearer header to the request.
The value of the header will be the current access token.
Implements AuthorizationCredential.
void Clear | ( | ) |
Clears all the values in the credential but does not revoke any tokens.
int64 expiration_timestamp_secs | ( | ) | const [inline] |
Returns the timestamp (in epoch seconds) when the access token will expire.
OAuth2AuthorizationFlow* flow | ( | ) | const [inline] |
Returns the flow currently bound.
virtual util::Status Load | ( | DataReader * | reader | ) | [virtual] |
Resets the credential from the JSON data in the reader.
[in] | reader | The JSON stream containing the credential attributes. |
Implements AuthorizationCredential.
virtual DataReader* MakeDataReader | ( | ) | const [virtual] |
Serializes the credential as a JSON stream.
Implements AuthorizationCredential.
ThreadsafeString* mutable_access_token | ( | ) | [inline] |
Returns a modifiable access token.
ThreadsafeString* mutable_refresh_token | ( | ) | [inline] |
Returns a modifiable access token.
virtual util::Status Refresh | ( | ) | [virtual] |
Attempts to refresh the credential.
This will certainly fail if there is no flow bound.
Implements AuthorizationCredential.
const ThreadsafeString& refresh_token | ( | ) | const [inline] |
Returns the refresh token.
void set_access_token | ( | const StringPiece & | access_token | ) | [inline] |
Sets the access token.
[in] | access_token | The access token provided by the OAuth 2.0 server. |
void set_expiration_timestamp_secs | ( | int64 | secs | ) | [inline] |
Sets the timestamp (in epoch seconds) when the access token will expire.
[in] | secs | Absolute value of epoch seconds. |
void set_flow | ( | OAuth2AuthorizationFlow * | flow | ) | [inline] |
Binds a flow to this instance so that it can support Refresh().
[in] | flow | NULL unbinds the flow. Otherwise, the caller retains ownership of the flow so must keep it active. |
void set_refresh_token | ( | const StringPiece & | refresh_token | ) | [inline] |
Sets the refresh token.
[in] | refresh_token | The refresh token provided by the OAuth 2.0 server. |
void set_user_id | ( | const StringPiece & | user_id, |
bool | verified | ||
) | [inline] |
Set the user_id for the credential.
[in] | user_id | The user_id will be copied into the credental. |
[in] | verified | Whether or not the user_id has been verified as true. |
virtual const StringPiece type | ( | ) | const [virtual] |
Identifies this as an kOAuth2Type credential.
Implements AuthorizationCredential.
virtual util::Status Update | ( | DataReader * | reader | ) | [virtual] |
Updates the credential attributes from the JSON data in the reader.
Unlike Load(), any attributes not explicitly specified in the reader data will be left as is.
[in] | reader | The JSON stream containing the credential attributes to update. |
util::Status UpdateFromString | ( | const StringPiece & | json | ) |
Updates the credential from a JSON string.
Existing properties not present in the json are left as is.
[in] | json | The JSON string containing the attributes to update. |
const string& user_id | ( | ) | const [inline] |
Returns the user ID associated with this credential, if known.
The user_id is not used for runtime authentication. It is normally used for managing persistence but certain flows such as web flow may use it as a login_hint.
bool user_id_verified | ( | ) | const [inline] |
Returns true if the user_id has been verified to be the actual user id that authorized access.
const StringPiece kOAuth2CredentialType [static] |
The AuthorizationCredential type identfying OAuth 2.0 credentials.