Utilities for authentication and authorization.
webapp2_extras.auth.default_config = {'user_model': 'webapp2_extras.appengine.auth.models.User', 'token_new_age': 86400, 'cookie_name': 'auth', 'token_max_age': 1814400, 'token_cache_age': 3600, 'user_attributes': [], 'session_backend': 'securecookie'}¶Default configuration values for this module. Keys are:
webapp2_extras.appengine.auth.models.User.max_age for
persistent auth sessions. Default is 86400 * 7 * 3 (3 weeks).webapp2_extras.auth.AuthStore(app, config=None)[source]¶Provides common utilities and configuration for Auth.
__init__(app, config=None)[source]¶Initializes the session store.
| Parameters: |
|
|---|
webapp2_extras.auth.Auth(request)[source]¶Authentication provider for a single request.
__init__(request)[source]¶Initializes the auth provider for a request.
| Parameters: | request – A webapp2.Request instance. |
|---|
get_user_by_password(auth_id, password, remember=False, save_session=True, silent=False)[source]¶Returns a user based on password credentials.
| Parameters: |
|
|---|---|
| Returns: | A user dict or None. |
| Raises: |
|
get_user_by_session(save_session=True)[source]¶Returns a user based on the current session.
| Parameters: | save_session – If True, saves the user in the session if authentication succeeds. |
|---|---|
| Returns: | A user dict or None. |
get_user_by_token(user_id, token, token_ts=None, cache=None, cache_ts=None, remember=False, save_session=True)[source]¶Returns a user based on an authentication token.
| Parameters: |
|
|---|---|
| Returns: | A user dict or None. |
set_session(user, token=None, token_ts=None, cache_ts=None, remember=False, **session_args)[source]¶Saves a user in the session.
| Parameters: |
|
|---|---|
| Remember: | If True, session is set to be persisted. |
webapp2_extras.auth.get_store(factory=<class 'webapp2_extras.auth.AuthStore'>, key='webapp2_extras.auth.Auth', app=None)[source]¶Returns an instance of AuthStore from the app registry.
It’ll try to get it from the current app registry, and if it is not registered it’ll be instantiated and registered. A second call to this function will return the same instance.
| Parameters: |
|
|---|
webapp2_extras.auth.set_store(store, key='webapp2_extras.auth.Auth', app=None)[source]¶Sets an instance of AuthStore in the app registry.
| Parameters: |
|
|---|
webapp2_extras.auth.get_auth(factory=<class 'webapp2_extras.auth.Auth'>, key='webapp2_extras.auth.Auth', request=None)[source]¶Returns an instance of Auth from the request registry.
It’ll try to get it from the current request registry, and if it is not registered it’ll be instantiated and registered. A second call to this function will return the same instance.
| Parameters: |
|
|---|
webapp2_extras.auth.set_auth(auth, key='webapp2_extras.auth.Auth', request=None)[source]¶Sets an instance of Auth in the request registry.
| Parameters: |
|
|---|