Google APIs Client Library for C++
OAuth2Credential Class Reference

Specifies an OAuth 2.0 Credential. More...

#include "client/auth/oauth2_authorization.h"

+ Inheritance diagram for OAuth2Credential:

List of all members.

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().
OAuth2AuthorizationFlowflow () 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 ThreadsafeStringaccess_token () const
 Returns the access token.
ThreadsafeStringmutable_access_token ()
 Returns a modifiable access token.
const ThreadsafeStringrefresh_token () const
 Returns the refresh token.
ThreadsafeStringmutable_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 DataReaderMakeDataReader () 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.

Detailed Description

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.

See also:
OAuth2AuthorizationFlow::RefreshCredentialWithOptions()
CredentialStore

Constructor & Destructor Documentation

Constructs an empty credential.

See also:
Load()

Standard destructor.


Member Function Documentation

const ThreadsafeString& access_token ( ) const [inline]

Returns the access token.

The access token might no longer be valid.

Returns:
to get the value, take .as_string() from the result.
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.

Returns:
Absolute value of epoch seconds might have already passed.
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.

Parameters:
[in]readerThe JSON stream containing the credential attributes.
Returns:
status indicating whether the credential values could be reset.
See also:
Update()

Implements AuthorizationCredential.

virtual DataReader* MakeDataReader ( ) const [virtual]

Serializes the credential as a JSON stream.

Returns:
an in-memory data reader specifying the credential.

Implements AuthorizationCredential.

Returns a modifiable access token.

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.

Returns:
ok on success or reason for failure.

Implements AuthorizationCredential.

const ThreadsafeString& refresh_token ( ) const [inline]

Returns the refresh token.

Returns:
to get the value, take .as_string() from the result.
void set_access_token ( const StringPiece &  access_token) [inline]

Sets the access token.

Parameters:
[in]access_tokenThe access token provided by the OAuth 2.0 server.
See also:
OAuth2ExchangeAuthorizationCodeRequest
OAuth2RefreshTokenRequest
void set_expiration_timestamp_secs ( int64  secs) [inline]

Sets the timestamp (in epoch seconds) when the access token will expire.

Parameters:
[in]secsAbsolute value of epoch seconds.
void set_flow ( OAuth2AuthorizationFlow flow) [inline]

Binds a flow to this instance so that it can support Refresh().

Parameters:
[in]flowNULL 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.

Parameters:
[in]refresh_tokenThe refresh token provided by the OAuth 2.0 server.
See also:
OAuth2ExchangeAuthorizationCodeRequest
void set_user_id ( const StringPiece &  user_id,
bool  verified 
) [inline]

Set the user_id for the credential.

Parameters:
[in]user_idThe user_id will be copied into the credental.
[in]verifiedWhether 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.

Parameters:
[in]readerThe JSON stream containing the credential attributes to update.
Returns:
status indicating whether the credential values could be updated.
util::Status UpdateFromString ( const StringPiece &  json)

Updates the credential from a JSON string.

Existing properties not present in the json are left as is.

Parameters:
[in]jsonThe JSON string containing the attributes to update.
Returns:
fail if the JSON argument was not valid.
See also:
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.

Warning:
The client application may have set the user id different from the source which actually authorized the user, making these out of sync.
See also:
user_id_verified
bool user_id_verified ( ) const [inline]

Returns true if the user_id has been verified to be the actual user id that authorized access.

Warning:
even if this is true, this data structure might not have come from a secure source so this attribute might be compramised.

Member Data Documentation

const StringPiece kOAuth2CredentialType [static]

The AuthorizationCredential type identfying OAuth 2.0 credentials.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines