Skip to main content

Tanker user token library

Project description

User token generation in Python for the Tanker SDK.

https://travis-ci.org/TankerHQ/user-token-python.svg?branch=master https://img.shields.io/pypi/v/tankersdk-user-token.svg

Installation

With pip:

$ pip install tankersdk-user-token

Usage

import tankersdk.usertoken

def retrieve_user_token(user_id):
    """ Fetch a previously stored token """
    ...


 def store_user_token(user_id, token):
    """ Store a previously generated token """
    ...


 def check_auth(user_id):
    """ Check the user is authenticated """
    ...


def serve_user_token(user_id):
    """ Called during sign/up sign in of your users.

    Send a user token, generated if necessary, but only to
    authenticated users
    """
    authorized = check_auth(user_id)
    if not authorized:
        raise UnAuthorizedError()

    token = retrieve_user_token(user_id)

    if not token:
      token = tankersdk.usertoken.generate_user_token(trustchain_id, trustchain_private_key, user_id)
      store_user_token(user_id, token)

    return token

Going further

Read more about user tokens in the Tanker guide.

Check the examples folder for usage examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tankersdk-user-token-0.3.tar.gz (3.9 kB view hashes)

Uploaded source

Built Distribution

tankersdk_user_token-0.3-py2.py3-none-any.whl (5.7 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page