Skip to content

Complete JWT authentication tutorial with vanilla python, no extra framework is used in the implementation.

License

Notifications You must be signed in to change notification settings

nemesisrc/jwt-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

JWT Authentication with Python

Python JWT License

A simple and straightforward tutorial on how to implement JWT (JSON Web Token) authentication in Python using the PyJWT library.

πŸš€ Features

  • Encode: Create a JWT token from a payload.
  • Decode: Verify and decode a JWT token to get the original payload.
  • Custom Signing Key: Use your own secret key to sign the tokens.

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

βš™οΈ Installation

  1. Clone the repository:

    git clone https://github.com/nemesisrc/jwt-authentication-python.git
    cd jwt-authentication-python
  2. Install the required dependencies:

    pip install pyjwt

▢️ Usage

To run the script, simply execute the main.py file:

python main.py

You will see the generated JWT token and the decoded payload printed to the console.

πŸ“„ Code Explanation

The main.py script demonstrates the basic functionality of creating and verifying JWT tokens.

  • signing_key: A secret key used to sign and verify the JWT tokens. Important: In a real-world application, this should be a much more complex and securely stored secret.
  • payload: The data you want to store in the JWT. This can be any information you want to transmit securely.
  • headers: Optional headers for the JWT. The alg (algorithm) and typ (token type) are specified here.
  • jwt.encode(): This function takes the payload, signing key, and algorithm to create the JWT token.
  • jwt.decode()": This function takes the token and the signing key to decode it. It will raise an exception if the token is invalid or the signature doesn't match.

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Complete JWT authentication tutorial with vanilla python, no extra framework is used in the implementation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages