Giter Club home page Giter Club logo

wpcodevo / rust-axum-jwt-rs256 Goto Github PK

View Code? Open in Web Editor NEW
43.0 1.0 1.0 64 KB

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.

Home Page: https://codevoweb.com/rust-and-axum-jwt-access-and-refresh-tokens/

Makefile 2.45% Rust 97.55%
assymetric-encryption authentication axum axum-framework docker jsonwebtoken jwt jwt-authentication postgresql private-keys

rust-axum-jwt-rs256's Introduction

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

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
  • Conclusion

Read the entire article here: https://codevoweb.com/rust-and-axum-jwt-access-and-refresh-tokens/

rust-axum-jwt-rs256's People

Contributors

wpcodevo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

axxon-n

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.