Skip to main content

Asymmetric key based authentication for HTTP APIs

Project description

https://img.shields.io/pypi/v/asymmetric_jwt_auth.svg https://travis-ci.org/crgwbr/asymmetric-jwt-auth.svg

What?

This is an library designed to handle authentication in server-to-server API requests. It accomplishes this using RSA public / private key pairs.

Why?

The standard pattern of using username and password works well for user-to-server requests, but is lacking for server-to-server applications. In these scenarios, since the password doesn’t need to be memorable by a user, we can use something far more secure: asymmetric key cryptography. This has the advantage that a password is never actually sent to the server.

How?

A public / private key pair is generated by the client machine. The server machine is then supplied with the public key, which it can store in any method it likes. When this library is used with Django, it provides a model for storing public keys associated with built-in User objects. When a request is made, the client creates a JWT including several claims and signs it using it’s private key. Upon receipt, the server verifies the claim to using the public key to ensure the issuer is legitimately who they claim to be.

The claim (issued by the client) includes components: the username of the user who is attempting authentication, the current unix timestamp, and a randomly generated nonce. For example:

{
    "username": "guido",
    "time": 1439216312,
    "nonce": "1"
}

The timestamp must be within ±20 seconds of the server time and the nonce must be unique within the given timestamp and user. In other words, if more than one request from a user is made within the same second, the nonce must change. Due to these two factors no token is usable more than once, thereby preventing replay attacks.

To make an authenticated request, the client must generate a JWT following the above format and include it as the HTTP Authorization header in the following format:

Authorization: JWT <my_token>

Important note: the claim is not encrypted, only signed. Additionally, the signature only prevents the claim from being tampered with or re-used. Every other part of the request is still vulnerable to tamper. Therefore, this is not a replacement for using SSL in the transport layer.

Full Documentation: https://asymmetric-jwt-auth.readthedocs.io

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

asymmetric_jwt_auth-1.0.0b1.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

asymmetric_jwt_auth-1.0.0b1-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file asymmetric_jwt_auth-1.0.0b1.tar.gz.

File metadata

  • Download URL: asymmetric_jwt_auth-1.0.0b1.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for asymmetric_jwt_auth-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 2fe52cf5931f6495568870a9df2eaee02dbd0fee5b36c13e040043cb40f2123a
MD5 a22f152ec97baa77fd170cdaa8322ead
BLAKE2b-256 350759589e4a1714cafab1a89e10b59c6b45aac87b8815e0baa3a38d8b74877e

See more details on using hashes here.

File details

Details for the file asymmetric_jwt_auth-1.0.0b1-py3-none-any.whl.

File metadata

  • Download URL: asymmetric_jwt_auth-1.0.0b1-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for asymmetric_jwt_auth-1.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee6dfc4df657ec73a483318fa2758eaea9fca94abbc93a4aa58be6976a092d84
MD5 b4f0fd78dcbb69a1c0d79f3abd7819d3
BLAKE2b-256 848a058bbe81a062e99e3e456ccc532b2e0efc82d0811ff531fe32dbb1c2d822

See more details on using hashes here.

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