Python
Getting started
You can add it to your requirements.txt file with:
1tcell_hooks==1.0.0
Then run pip install -r requirements.txt
There are two options for calling the hooks from your application code:
Providing a Django/Flask request object and having the tCell Agent extract the relevant details from it:
1from tcell_hooks.v1 import send_django_login_event, LOGIN_SUCCESS23send_django_login_event(4status=LOGIN_SUCCESS,5django_request=request,6user_id="tcell@tcell.io",7session_id="124KDJFL3234"8)9from tcell_hooks.v1 import send_flask_login_event, LOGIN_SUCCESS1011send_flask_login_event(12status=LOGIN_SUCCESS,13flask_request=request,14user_id="tcell@tcell.io",15session_id="124KDJFL3234"16)Providing each individual piece of information required for the tCell event:
1from tcell_hooks.v1 import send_login_event, LOGIN_SUCCESS23send_login_event(4status=LOGIN_SUCCESS,5session_id="124KDJFL3234",6user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) ...",7referrer="http://192.168.99.100:3000/",8remote_address="192.168.99.1",9header_keys=["HOST", "USER_AGENT", "ACCEPT", "REFERER", "ACCEPT_ENCODING", "ACCEPT_LANGUAGE", "COOKIE"],10user_id="tcell@tcell.io",11document_uri="/users/auth/doorkeeper/callbackuri"12)
The available statuses are:
LOGIN_SUCCESS
LOGIN_FAILURE
API Documentation
Report a Login event by providing a Django request object
1def send_django_login_event(status,2django_request,3user_id,4session_id,5user_valid=None):
- status (string) : tcell_hooks.v1.LOGIN_SUCCESS or tcell_hooks.v1.LOGIN_FAILURE
- django_request (Object) : Request object provided by Django
- user_id (string) : Identification used for the user (i.e. email, username)
- session_id (string) : Session ID for user logging in. This will be hmac'ed by the Agent before being sent.
- user_valid (boolean) : (Optional) Set as true if exists, otherwise false. Defaults nil.
Report a Login event by providing a Flask request object
1def send_flask_login_event(status,2flask_request,3user_id,4session_id,5user_valid=None):
- status (string) : tcell_hooks.v1.LOGIN_SUCCESS or tcell_hooks.v1.LOGIN_FAILURE
- flask_request (Object) : Request object provided by Flask
- user_id (string) : Identification used for the user (i.e. email, username)
- session_id (string) : Session ID for user logging in. This will be hmac'ed by the Agent before being sent.
- user_valid (boolean) : (Optional) Set as true if exists, otherwise false. Defaults nil.
Report a Login event by providing all the necessary parameters for a tCell event
1def send_login_event(status,2session_id,3user_agent,4referrer,5remote_address,6header_keys,7user_id,8document_uri,9user_valid=None):
- status (string) : tcell_hooks.v1.LOGIN_SUCCESS or tcell_hooks.v1.LOGIN_FAILURE
- session_id (string) : Session ID for user logging in. This will be hmac'ed by the Agent before being sent.
- user_agent (string) : User agent taken from header
- referrer (string) : Referrer taken from header
- remote_addr (string) : IP of the Request
- header_keys (string) : An array of the header keys. The order is important (do not sort the array)
- user_id (string) : Identification used for the user (i.e. email, username)
- document_uri (string) : Document URI taken from request
- user_valid (boolean) : (Optional) Set as true if exists, otherwise false. Defaults nil.
Important
If the tcell_agent is not installed or if it's disabled, this code will do nothing and should have no performance effect on your app.
Password Hash
When you send a secured hashed password to the tCell cloud, you create a more robust Account Takeover response. See Password Hash for more information.
Did this page help you?