Package oauth2client :: Module appengine :: Class OAuth2Decorator
[hide private]
[frames] | no frames]

Class OAuth2Decorator

source code


Utility for making OAuth 2.0 easier.

Instantiate and then use with oauth_required or oauth_aware
as decorators on webapp.RequestHandler methods.

Example:

  decorator = OAuth2Decorator(
      client_id='837...ent.com',
      client_secret='Qh...wwI',
      scope='https://www.googleapis.com/auth/plus')


  class MainHandler(webapp.RequestHandler):

    @decorator.oauth_required
    def get(self):
      http = decorator.http()
      # http is authorized with the user's Credentials and can be used
      # in API calls

Instance Methods [hide private]
 
__init__(self, client_id, client_secret, scope, auth_uri='https://accounts.google.com/o/oauth2/auth', token_uri='https://accounts.google.com/o/oauth2/token', user_agent=None, message=None, **kwargs)
Constructor for OAuth2Decorator
source code
 
_display_error_message(self, request_handler) source code
 
oauth_required(self, method)
Decorator that starts the OAuth 2.0 dance.
source code
 
oauth_aware(self, method)
Decorator that sets up for OAuth 2.0 dance, but doesn't do it.
source code
 
has_credentials(self)
True if for the logged in user there are valid access Credentials.
source code
 
authorize_url(self)
Returns the URL to start the OAuth dance.
source code
 
http(self)
Returns an authorized http instance.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, client_id, client_secret, scope, auth_uri='https://accounts.google.com/o/oauth2/auth', token_uri='https://accounts.google.com/o/oauth2/token', user_agent=None, message=None, **kwargs)
(Constructor)

source code 
Constructor for OAuth2Decorator

Args:
  client_id: string, client identifier.
  client_secret: string client secret.
  scope: string or list of strings, scope(s) of the credentials being
    requested.
  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.
  user_agent: string, User agent of your application, default to None.
  message: Message to display if there are problems with the OAuth 2.0
    configuration. The message may contain HTML and will be presented on the
    web interface for any method that uses the decorator.
  **kwargs: dict, Keyword arguments are be passed along as kwargs to the
    OAuth2WebServerFlow constructor.

Overrides: object.__init__

oauth_required(self, method)

source code 
Decorator that starts the OAuth 2.0 dance.

Starts the OAuth dance for the logged in user if they haven't already
granted access for this application.

Args:
  method: callable, to be decorated method of a webapp.RequestHandler
    instance.

oauth_aware(self, method)

source code 
Decorator that sets up for OAuth 2.0 dance, but doesn't do it.

Does all the setup for the OAuth dance, but doesn't initiate it.
This decorator is useful if you want to create a page that knows
whether or not the user has granted access to this application.
From within a method decorated with @oauth_aware the has_credentials()
and authorize_url() methods can be called.

Args:
  method: callable, to be decorated method of a webapp.RequestHandler
    instance.

has_credentials(self)

source code 
True if for the logged in user there are valid access Credentials.

Must only be called from with a webapp.RequestHandler subclassed method
that had been decorated with either @oauth_required or @oauth_aware.

authorize_url(self)

source code 
Returns the URL to start the OAuth dance.

Must only be called from with a webapp.RequestHandler subclassed method
that had been decorated with either @oauth_required or @oauth_aware.

http(self)

source code 
Returns an authorized http instance.

Must only be called from within an @oauth_required decorated method, or
from within an @oauth_aware decorated method where has_credentials()
returns True.