Skip to main content

Asynchronous python Library for justauthenticate.me authentication

Project description

python_jam

Build Status

An asynchronous python implementation of Just Authenticate Me's REST Api.

Installation

Install normally from pypi.org:

pip install python-jam

It depends on aiohttp, so if aiohttp is installed with extras or speedups, those will be used automatically. It will also use ujson for serialization if installed. ( Defaults to build-in json)

Basic Usage

Create the JustAuthenticateMe object by supplying the AppId from you Just Authenticate Me app, then call the corresponding functions as needed. The primary ones are in the example below.

from python_jam import (
    JustAuthenticateMe, JAMUnauthorized, JAMBadRequest,
    JAMNotVerified
)

jam = JustAuthenticateMe('APP_ID')

try:
    await jam.authenticate('user@example.com')
except JAMBadRequest as e:
    print("Something went wrong", e)

try:
    headers, claims = await jam.verify_token('user_id_token')
except JAMNotVerified:
    print("Unauthorized, invalid token")

try:
    new_token = await jam.refresh('user_refresh_token')
except JAMBadRequest as e:
    print("Refresh not allowed", e)
except JAMUnauthorized:
    print("invalid refresh token")

Available Methods

These are the methods available on a JustAuthenticateMe instance. All Exception inherit from JustAuthenticateMeError. This is also the exception raised by an unexpected error. If the JustAuthenticateMe api returns a message with the error, that is passed through as exception text.

  • jam.authenticate(email) - Initialize authentication flow for a user given an email address. Returns None on success. Raises JAMBadRequest when a 400 bad request is received from justauthenticate.me (usually an invalid email) or JAMNotFound When a 404 not found is received back from justauthenticate.me

  • jam.verify_token(id_token) - Verify a JustAuthenticateMe token against jwks (loaded lazily). Call with parameter id_token (jwt) from JustAuthenticateMe. Returns headers, claims: headers and claims encoded in the user jwt. (passed through from python-jwt) or raises JAMNotVerified if verification fails on a token.

  • jam.refresh(refresh_token) - Refresh id tokens with refresh token. refresh_token: user's refreshToken from JustAuthenticateMe. Returns: new idToken (JWT) from JustAuthenticateMe. Raises JAMBadRequest when app doesn't allow refresh or request is malformed. Raises JAMInvalid when the refresh token was invalid. Raises JAMNotFound when the appId or refresh token was not found.

  • jam.delete_refresh_token(id_token, refresh_token) - Delete a user's refresh token. (i.e. logout) Called with id_token: User's id token (JWT) from Just Authenticate Me, and refresh_token: The refresh token to delete. Returns None or raises JAMUnauthorized when the id_token is invalid or JAMNotFound when the refresh_token or app_id cannot be found

  • jam.delete_all_refresh_tokens(id_token) - Delete all of a user's refresh tokens. (i.e. logout) Called with id_token: User's id token (JWT) from Just Authenticate Me. Returns None or raises JAMUnauthorized when the id_token is invalid.

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

python-jam-1.0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

python_jam-1.0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file python-jam-1.0.1.tar.gz.

File metadata

  • Download URL: python-jam-1.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.8.0-28-generic

File hashes

Hashes for python-jam-1.0.1.tar.gz
Algorithm Hash digest
SHA256 af430ac07e2771460583e0a1060d0fbb150288207fdc18b51755a3c1fd07b44f
MD5 ed8ce69df945de2c3b807c8d0906dc35
BLAKE2b-256 075ef064b2baa730e4f732b7f4a1774da3bbed666f8f0840a4143efd6c7983c1

See more details on using hashes here.

Provenance

File details

Details for the file python_jam-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: python_jam-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.8.0-28-generic

File hashes

Hashes for python_jam-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8bc8d7e2a31f32becb8d04619472a3fbe61f70b0fc7e2fb3aa72b33214100ca5
MD5 085c0f9da6e0e168cf26bebea3f524ec
BLAKE2b-256 384a77c86eef193445b4df5520da735e621ef144b6e0dc6d47edfdf9d327c026

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page