Python

Getting started

You can add it to your requirements.txt file with:

1
tcell_hooks==1.0.0

Then run pip install -r requirements.txt

There are two options for calling the hooks from your application code:

  1. Providing a Django/Flask request object and having the tCell Agent extract the relevant details from it:

    1
    from tcell_hooks.v1 import send_django_login_event, LOGIN_SUCCESS
    2
    3
    send_django_login_event(
    4
    status=LOGIN_SUCCESS,
    5
    django_request=request,
    6
    user_id="tcell@tcell.io",
    7
    session_id="124KDJFL3234"
    8
    )
    9
    from tcell_hooks.v1 import send_flask_login_event, LOGIN_SUCCESS
    10
    11
    send_flask_login_event(
    12
    status=LOGIN_SUCCESS,
    13
    flask_request=request,
    14
    user_id="tcell@tcell.io",
    15
    session_id="124KDJFL3234"
    16
    )
  2. Providing each individual piece of information required for the tCell event:

    1
    from tcell_hooks.v1 import send_login_event, LOGIN_SUCCESS
    2
    3
    send_login_event(
    4
    status=LOGIN_SUCCESS,
    5
    session_id="124KDJFL3234",
    6
    user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) ...",
    7
    referrer="http://192.168.99.100:3000/",
    8
    remote_address="192.168.99.1",
    9
    header_keys=["HOST", "USER_AGENT", "ACCEPT", "REFERER", "ACCEPT_ENCODING", "ACCEPT_LANGUAGE", "COOKIE"],
    10
    user_id="tcell@tcell.io",
    11
    document_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

1
def send_django_login_event(status,
2
django_request,
3
user_id,
4
session_id,
5
user_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

1
def send_flask_login_event(status,
2
flask_request,
3
user_id,
4
session_id,
5
user_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

1
def send_login_event(status,
2
session_id,
3
user_agent,
4
referrer,
5
remote_address,
6
header_keys,
7
user_id,
8
document_uri,
9
user_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.