Skip to main content

Asymmetric key based authentication for HTTP APIs

Project description

https://img.shields.io/pypi/v/asymmetric_jwt_auth.svg https://gitlab.com/crgwbr/asymmetric_jwt_auth/badges/master/pipeline.svg https://gitlab.com/crgwbr/asymmetric_jwt_auth/badges/master/coverage.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.2.1.tar.gz (71.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asymmetric_jwt_auth-1.2.1-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

Details for the file asymmetric_jwt_auth-1.2.1.tar.gz.

File metadata

  • Download URL: asymmetric_jwt_auth-1.2.1.tar.gz
  • Upload date:
  • Size: 71.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for asymmetric_jwt_auth-1.2.1.tar.gz
Algorithm Hash digest
SHA256 174339ba33c52d276cd26e98ee79bcdfc91270b435acae33ba3f5633f5d970e0
MD5 6c917150bd970dd91adcf8b721dc7941
BLAKE2b-256 a26f6dd23eb2b5720771c9420ec8e4cdc268d5e7398ff75d2259a2aa4d60e6b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymmetric_jwt_auth-1.2.1.tar.gz:

Publisher: .gitlab-ci.yml on thelabnyc/asymmetric-jwt-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asymmetric_jwt_auth-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for asymmetric_jwt_auth-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 755d2c3fa71ad37d1eed8baf57fd60b6204500b2c796bd02687064814d9765dd
MD5 687d36df7d845ca67dd29932152070eb
BLAKE2b-256 86ebea4831332271f563e9b28fe02b475e0ae105d7b5822f45322b45175dab51

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymmetric_jwt_auth-1.2.1-py3-none-any.whl:

Publisher: .gitlab-ci.yml on thelabnyc/asymmetric-jwt-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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