| |
- __builtin__.object
-
- Credentials
-
- OAuth2Credentials
-
- AccessTokenCredentials
- Flow
-
- OAuth2WebServerFlow
- Storage
- exceptions.Exception(exceptions.BaseException)
-
- Error
-
- AccessTokenCredentialsError
- AccessTokenRefreshError
- FlowExchangeError
class AccessTokenCredentials(OAuth2Credentials) |
|
Credentials object for OAuth 2.0
Credentials can be applied to an httplib2.Http object using the authorize()
method, which then signs each request from that object with the OAuth 2.0
access token. This set of credentials is for the use case where you have
acquired an OAuth 2.0 access_token from another place such as a JavaScript
client or another web application, and wish to use it from Python. Because
only the access_token is present it can not be refreshed and will in time
expire.
AccessTokenCredentials objects may be safely pickled and unpickled.
Usage:
credentials = AccessTokenCredentials('<an access token>',
'my-user-agent/1.0')
http = httplib2.Http()
http = credentials.authorize(http)
Exceptions:
AccessTokenCredentialsExpired: raised when the access_token expires or is
revoked. |
|
- Method resolution order:
- AccessTokenCredentials
- OAuth2Credentials
- Credentials
- __builtin__.object
Methods defined here:
- __init__(self, access_token, user_agent)
- Create an instance of OAuth2Credentials
This is one of the few types if Credentials that you should contrust,
Credentials objects are usually instantiated by a Flow.
Args:
access_token: string, access token.
user_agent: string, The HTTP User-Agent to provide for this application.
Notes:
store: callable, a callable that when passed a Credential
will store the credential back to where it came from.
Methods inherited from OAuth2Credentials:
- __getstate__(self)
- Trim the state down to something that can be pickled.
- __setstate__(self, state)
- Reconstitute the state of the object from being pickled.
- authorize(self, http)
- Authorize an httplib2.Http instance with these credentials.
Args:
http: An instance of httplib2.Http
or something that acts like it.
Returns:
A modified instance of http that was passed in.
Example:
h = httplib2.Http()
h = credentials.authorize(h)
You can't create a new OAuth
subclass of httplib2.Authenication because
it never gets passed the absolute URI, which is
needed for signing. So instead we have to overload
'request' with a closure that adds in the
Authorization header and then calls the original version
of 'request()'.
- set_store(self, store)
- Set the storage for the credential.
Args:
store: callable, a callable that when passed a Credential
will store the credential back to where it came from.
This is needed to store the latest access_token if it
has expired and been refreshed.
Data descriptors inherited from OAuth2Credentials:
- invalid
- True if the credentials are invalid, such as being revoked.
Data descriptors inherited from Credentials:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class Credentials(__builtin__.object) |
|
Base class for all Credentials objects.
Subclasses must define an authorize() method
that applies the credentials to an HTTP transport. |
|
Methods defined here:
- authorize(self, http)
- Take an httplib2.Http instance (or equivalent) and
authorizes it for the set of credentials, usually by
replacing http.request() with a method that adds in
the appropriate headers and then delegates to the original
Http.request() method.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class Flow(__builtin__.object) |
|
Base class for all Flow objects. |
|
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class OAuth2Credentials(Credentials) |
|
Credentials object for OAuth 2.0
Credentials can be applied to an httplib2.Http object using the authorize()
method, which then signs each request from that object with the OAuth 2.0
access token.
OAuth2Credentials objects may be safely pickled and unpickled. |
|
- Method resolution order:
- OAuth2Credentials
- Credentials
- __builtin__.object
Methods defined here:
- __getstate__(self)
- Trim the state down to something that can be pickled.
- __init__(self, access_token, client_id, client_secret, refresh_token, token_expiry, token_uri, user_agent)
- Create an instance of OAuth2Credentials
This constructor is not usually called by the user, instead
OAuth2Credentials objects are instantiated by the OAuth2WebServerFlow.
Args:
token_uri: string, URI of token endpoint.
client_id: string, client identifier.
client_secret: string, client secret.
access_token: string, access token.
token_expiry: datetime, when the access_token expires.
refresh_token: string, refresh token.
user_agent: string, The HTTP User-Agent to provide for this application.
Notes:
store: callable, a callable that when passed a Credential
will store the credential back to where it came from.
This is needed to store the latest access_token if it
has expired and been refreshed.
- __setstate__(self, state)
- Reconstitute the state of the object from being pickled.
- authorize(self, http)
- Authorize an httplib2.Http instance with these credentials.
Args:
http: An instance of httplib2.Http
or something that acts like it.
Returns:
A modified instance of http that was passed in.
Example:
h = httplib2.Http()
h = credentials.authorize(h)
You can't create a new OAuth
subclass of httplib2.Authenication because
it never gets passed the absolute URI, which is
needed for signing. So instead we have to overload
'request' with a closure that adds in the
Authorization header and then calls the original version
of 'request()'.
- set_store(self, store)
- Set the storage for the credential.
Args:
store: callable, a callable that when passed a Credential
will store the credential back to where it came from.
This is needed to store the latest access_token if it
has expired and been refreshed.
Data descriptors defined here:
- invalid
- True if the credentials are invalid, such as being revoked.
Data descriptors inherited from Credentials:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class OAuth2WebServerFlow(Flow) |
|
Does the Web Server Flow for OAuth 2.0.
OAuth2Credentials objects may be safely pickled and unpickled. |
|
- Method resolution order:
- OAuth2WebServerFlow
- Flow
- __builtin__.object
Methods defined here:
- __init__(self, client_id, client_secret, scope, user_agent, auth_uri='https://accounts.google.com/o/oauth2/auth', token_uri='https://accounts.google.com/o/oauth2/token', **kwargs)
- Constructor for OAuth2WebServerFlow
Args:
client_id: string, client identifier.
client_secret: string client secret.
scope: string, scope of the credentials being requested.
user_agent: string, HTTP User-Agent to provide for this application.
auth_uri: string, URI for authorization endpoint. For convenience
defaults to Google's endpoints but any OAuth 2.0 provider can be used.
token_uri: string, URI for token endpoint. For convenience
defaults to Google's endpoints but any OAuth 2.0 provider can be used.
**kwargs: dict, The keyword arguments are all optional and required
parameters for the OAuth calls.
- step1_get_authorize_url(self, redirect_uri='oob')
- Returns a URI to redirect to the provider.
Args:
redirect_uri: string, Either the string 'oob' for a non-web-based
application, or a URI that handles the callback from
the authorization server.
If redirect_uri is 'oob' then pass in the
generated verification code to step2_exchange,
otherwise pass in the query parameters received
at the callback uri to step2_exchange.
- step2_exchange(self, code, http=None)
- Exhanges a code for OAuth2Credentials.
Args:
code: string or dict, either the code as a string, or a dictionary
of the query parameters to the redirect_uri, which contains
the code.
http: httplib2.Http, optional http instance to use to do the fetch
Data descriptors inherited from Flow:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class Storage(__builtin__.object) |
|
Base class for all Storage objects.
Store and retrieve a single credential. |
|
Methods defined here:
- get(self)
- Retrieve credential.
Returns:
apiclient.oauth.Credentials
- put(self, credentials)
- Write a credential.
Args:
credentials: Credentials, the credentials to store.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |