Created
August 12, 2014 18:35
-
-
Save ricardodani/1177a04c8ade13bc9a49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AuthHive(object): | |
''' | |
The AuthHive is the responsible for integrating authentication into your API. | |
''' | |
@classmethod | |
def configure( | |
cls, app, secret_key, expiration=1200, cookie_name='AUTH_TOKEN', | |
authenticated_create=True, authenticated_update=True, | |
authenticated_delete=True, proxy_host=None, proxy_port=None, | |
proxy_username=None, proxy_password=None, authenticated_get=True | |
): | |
'''Configure the application to the authentication ecosystem. | |
:param app: The tornado application to configure | |
:type app: tornado.web.Application instance | |
:param secret_key: A string to use for encoding/decoding Jwt that must | |
be private | |
:type secret_key: str | |
:param expiration: Time in seconds to the expiration (time to live) of | |
the token | |
:type expiration: int | |
:param cookie_name: The name of the cookie | |
:type cookie_name: str | |
:param proxy_host: Host of the Proxy | |
:type proxy_host: str | |
:param proxy_port: Port of the Proxy | |
:type proxy_port: str | |
:param proxy_username: Username of the Proxy | |
:type proxy_username: str | |
:param proxy_password: Password of the Proxy | |
:type proxy_password: str | |
:param authenticated_get: Should check authentication when listen to | |
`bzz.pre-get-instance` and `bzz.pre-get-list` | |
signals. Default is `True` | |
:type authenticated_get: bool | |
:param authenticated_save: Should check authentication when listen to | |
`bzz.pre-create-instance` signal. Default is | |
`True` | |
:type authenticated_save: bool | |
:param authenticated_update: Should check authentication when listen to | |
`bzz.pre-update-instance` signal. Default is | |
`True` | |
:type authenticated_update: bool | |
:param authenticated_delete: Should check authentication when listen to | |
`bzz.pre-delete-instance` signal. Default is | |
`True` | |
:type authenticated_delete: bool | |
''' | |
app.authentication_options = { | |
'secret_key': secret_key, | |
'expiration': expiration, | |
'cookie_name': cookie_name, | |
'proxy_info': { | |
'proxy_port': proxy_port, | |
'proxy_host': proxy_host, | |
'proxy_username': proxy_username, | |
'proxy_password': proxy_password, | |
}, | |
'jwt': utils.Jwt(secret_key), | |
} | |
if authenticated_get: | |
signals.pre_get_instance.connect(cls.handle_check_auth) | |
signals.pre_get_list.connect(cls.handle_check_auth) | |
if authenticated_create: | |
signals.pre_create_instance.connect(cls.handle_check_auth) | |
if authenticated_update: | |
signals.pre_update_instance.connect(cls.handle_check_auth) | |
if authenticated_delete: | |
signals.pre_delete_instance.connect(cls.handle_check_auth) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment