Skip to main content
JWT Plugin

Understand how to use our JWT plugin to and expand your applications potential.

Adam avatar
Written by Adam
Updated over 6 months ago

Overview

This Bubble plugin provides three main actions for handling JSON Web Tokens (JWT): Creating, Decoding, and Verifying. These actions enable secure token generation, interpretation, and validation within your Bubble application.

Actions

1. Create JWT

2. Decode JWT

3. Verify JWT

Create JWT

Description

This action generates a JWT using the provided user information and a shared key. The token includes an issued at (iat) time, an expiration time (exp), and a unique JWT ID (jti).

Inputs

User Name (user_name): The name of the user for whom the token is being created.

User Email (user_email): The email address of the user for whom the token is being created.

Expiry (expiry): The expiration time for the token in seconds. Default is 3600 seconds (1 hour).

Outputs

JWT Token (jwt_token): The generated JWT.

Error (error): An error message if token generation fails.

Example Usage

1. Add the “Create JWT” action to your workflow.

2. Provide the necessary inputs: User Name, User Email, and Expiry.

3. The output will be the JWT Token or an error message if something goes wrong.

Decode JWT

Description

This action decodes a JWT and returns its payload. Note that this action does not verify the token’s signature.

Inputs

JWT Token (jwt_token): The JWT to decode.

Outputs

Decoded Payload (decoded_payload): The decoded payload of the JWT.

Error (error): An error message if token decoding fails.

Example Usage

1. Add the “Decode JWT” action to your workflow.

2. Provide the JWT Token as input.

3. The output will be the Decoded Payload or an error message if something goes wrong.

Verify JWT

Description

This action verifies a JWT using a shared key. It checks the token’s signature and ensures it has not expired.

Inputs

JWT Token (jwt_token): The JWT to verify.

Enable Logging (enableLogging): A boolean to enable or disable logging for debugging purposes.

Outputs

Verified (verified): A boolean indicating whether the JWT is valid.

Error (error): An error message if token verification fails.

Example Usage

1. Add the “Verify JWT” action to your workflow.

2. Provide the JWT Token and set Enable Logging if needed.

3. The output will be a boolean indicating if the JWT is valid or an error message if something goes wrong.

Refresh JWT

Description

This action refreshes an existing JWT by extending its expiration time. It uses the provided JWT token and a shared key to generate a new token with updated issued at (iat) and expiration (exp) times, as well as a new unique JWT ID (jti).

Inputs

JWT Token (jwt_token): The existing JWT token that needs to be refreshed.

Additional Time (additional_time): The additional time in seconds to extend the token’s expiration. Default is 3600 seconds (1 hour).

Outputs

JWT Token (jwt_token): The refreshed JWT.

Error (error): An error message if the token refresh fails.

Example Usage

  1. Add the “Refresh JWT” action to your workflow.

  2. Provide the necessary inputs: JWT Token and Additional Time.

  3. The output will be the refreshed JWT Token or an error message if something goes wrong.


Common Issues and Troubleshooting

1. Token Expiration: If a token has expired, the Verify JWT action will return an error indicating the token has expired. Ensure the token is refreshed before it expires.

2. Invalid Token: If the token is invalid or the shared key is incorrect, the Verify JWT action will return an error indicating verification failure. Ensure the correct token and key are used.

3. Missing Inputs: Ensure all required inputs are provided for each action. Missing inputs will result in errors.

Did this answer your question?