Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wpcodevo/rust-axum-jwt-rs256
In this article, you'll learn how to build a secure and efficient backend API in Rust with JWT access and refresh tokens functionality. We'll leverage the high-performance Axum framework and SQLX to store data in a PostgreSQL database.
https://github.com/wpcodevo/rust-axum-jwt-rs256
assymetric-encryption authentication axum axum-framework docker jsonwebtoken jwt jwt-authentication postgresql private-keys public-keys rs256 rust
Last synced: 2 months ago
JSON representation
In this article, you'll learn how to build a secure and efficient backend API in Rust with JWT access and refresh tokens functionality. We'll leverage the high-performance Axum framework and SQLX to store data in a PostgreSQL database.
- Host: GitHub
- URL: https://github.com/wpcodevo/rust-axum-jwt-rs256
- Owner: wpcodevo
- Created: 2023-04-03T21:41:38.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-27T10:14:54.000Z (about 1 year ago)
- Last Synced: 2024-05-15T15:32:46.688Z (9 months ago)
- Topics: assymetric-encryption, authentication, axum, axum-framework, docker, jsonwebtoken, jwt, jwt-authentication, postgresql, private-keys, public-keys, rs256, rust
- Language: Rust
- Homepage: https://codevoweb.com/rust-and-axum-jwt-access-and-refresh-tokens/
- Size: 62.5 KB
- Stars: 39
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust and Axum Framework: JWT Access and Refresh Tokens
In this article, you'll learn how to build a secure and efficient backend API in Rust with JWT access and refresh tokens functionality. We'll leverage the high-performance Axum framework and SQLX to store data in a PostgreSQL database.
![Rust and Axum Framework: JWT Access and Refresh Tokens](https://codevoweb.com/wp-content/uploads/2023/04/Rust-and-Axum-Framework-JWT-Access-and-Refresh-Tokens.webp)
## Topics Covered
- Set up and Run the Axum API on your Machine
- Run the Axum API with a Frontend App
- Set up the Rust Project with Cargo
- Launch PostgreSQL, Redis and pgAdmin Servers
- Perform Database Migration with SQLx-CLI
- Load the Environment Variables into the App
- Connect the Axum Server to the Redis and Postgres Servers
- Define the SQLX Database Model
- Define the API Response Structs
- Generate the RS256 Private and Public Keys
- Create Helper Functions to Sign and Verify the JWTs
- Function to Sign the JWT using the Private Key
- Function to Verify the JWT using the Public Key
- Create an Axum JWT Middleware Guard
- Implement the JWT Authentication Route Handlers
- Create Utility Functions
- Route Handler to Register Users
- Route Handler to Sign In Users
- Route Handler to Refresh the JWTs
- Route Handler to Logout Users
- Route Handler to Fetch the Authenticated User
- The Complete Code of the Route Handlers
- Create Axum Routes for the Handler Functions
- Register the Axum Router and Set up CORS
- ConclusionRead the entire article here: [https://codevoweb.com/rust-and-axum-jwt-access-and-refresh-tokens/](https://codevoweb.com/rust-and-axum-jwt-access-and-refresh-tokens/)