
Public Member Functions | |
| def | get_auth_http_client |
| def | get_authenticated_user |
Private Member Functions | |
| def | _on_access_token |
Static Private Attributes | |
| string | _OAUTH_ACCESS_TOKEN_URL = "https://accounts.google.com/o/oauth2/token" |
| string | _OAUTH_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth" |
| _OAUTH_NO_CALLBACKS = False | |
| string | _OAUTH_SETTINGS_KEY = 'google_oauth' |
Google authentication using OAuth2.
In order to use, register your application with Google and copy the
relevant parameters to your application settings.
* Go to the Google Dev Console at http://console.developers.google.com
* Select a project, or create a new one.
* In the sidebar on the left, select APIs & Auth.
* In the list of APIs, find the Google+ API service and set it to ON.
* In the sidebar on the left, select Credentials.
* In the OAuth section of the page, select Create New Client ID.
* Set the Redirect URI to point to your auth handler
* Copy the "Client secret" and "Client ID" to the application settings as
{"google_oauth": {"key": CLIENT_ID, "secret": CLIENT_SECRET}}
.. versionadded:: 3.2
| def tornado.auth.GoogleOAuth2Mixin._on_access_token | ( | self, | |
| future, | |||
| response | |||
| ) | [private] |
| def tornado.auth.GoogleOAuth2Mixin.get_authenticated_user | ( | self, | |
| redirect_uri, | |||
| code, | |||
| callback | |||
| ) |
Handles the login for the Google user, returning a user object.
Example usage::
class GoogleOAuth2LoginHandler(tornado.web.RequestHandler,
tornado.auth.GoogleOAuth2Mixin):
@tornado.gen.coroutine
def get(self):
if self.get_argument('code', False):
user = yield self.get_authenticated_user(
redirect_uri='http://your.site.com/auth/google',
code=self.get_argument('code'))
# Save the user with e.g. set_secure_cookie
else:
yield self.authorize_redirect(
redirect_uri='http://your.site.com/auth/google',
client_id=self.settings['google_oauth']['key'],
scope=['profile', 'email'],
response_type='code',
extra_params={'approval_prompt': 'auto'})
string tornado::auth.GoogleOAuth2Mixin::_OAUTH_ACCESS_TOKEN_URL = "https://accounts.google.com/o/oauth2/token" [static, private] |
string tornado::auth.GoogleOAuth2Mixin::_OAUTH_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth" [static, private] |
tornado::auth.GoogleOAuth2Mixin::_OAUTH_NO_CALLBACKS = False [static, private] |
string tornado::auth.GoogleOAuth2Mixin::_OAUTH_SETTINGS_KEY = 'google_oauth' [static, private] |