Skip to main content

JWT Generator for Nexmo

Project description

Nexmo Python JWT Generator

PyPI version Python versions supported Code style: black Downloads

Nexmo is now known as Vonage

Python class to assist with generating JWT tokens for use with the Nexmo API.

Learn more about Authenticating with JSON Web Tokens.

Installation

To install, run:

pip install nexmo-jwt

Usage

JWTokenGenerator is a python class that receives the application_id and private_key as required parameters in the constructor. Then a token is generated using the generate_token() method.

By default the generated token expires after 15 minutes, but this option can be configured using the set_expiration_iat method.

Generating a JWT

To generate token the application_id claim and the private_key are required. Using Nexmo Account as an example, you could enter to the Applications section and select a specific application. From there you can copy the application_id and Generate a new Public key, And then download the private key file.

Generating a JWT with Private Key Contents

To generate a JWT with these properties you can use:

from nexmo_jwt import JWTokenGenerator
gen: JWTokenGenerator = JWTokenGenerator('your-application-id','private key contents')
token: bytes = gen.generate_token()

Generating a JWT with Private Key Path

You can also provide a Path to the location of your private key:

from nexmo_jwt import JWTokenGenerator
gen: JWTokenGenerator = JWTokenGenerator('your-application-id','/path/to/your/private.key')
token: bytes = gen.generate_token()

Generating a JWT with Custom Claims

It is also possible to generate a JWT with custom data:

from nexmo_jwt import JWTokenGenerator
gen: JWTokenGenerator = JWTokenGenerator('your-application-id','/path/to/your/private.key')
token: bytes = gen.generate_token(payload={"foo", "bar"})

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

nexmo-jwt-1.0.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

nexmo_jwt-1.0.1-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

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