Skip to content

FastAPI extension that provides JWT Auth support (secure, easy to use, and lightweight)

Notifications You must be signed in to change notification settings

seanglynn/fastapi-jwt-auth

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI JWT Auth

  1. Copy environment configuration and update config

    cp example.env .env
  2. Install the requirements:

    poetry install -v
  3. Init python environment:

    poetry shell
  4. Run the app:

    python main.py
  5. Test at http://localhost:8080/docs

  6. Get bearer token by logging in with expected client configuration:

    curl -X 'POST' \
     'http://localhost:8080/client/login' \
     -H 'accept: application/json' \
     -H 'Content-Type: application/json' \
     -d '{"team_name": "ateam", "client_id": "123456789", "client_secret": "weaksecret"}'
  7. Use the bearer token returned from the last step to authenticate with protected endpoints.

    curl -X 'POST' \
      'http://localhost:8080/posts' \
      -H 'accept: application/json' \
      -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnRfaWQiOiIxMjM0NTY3ODkiLCJleHBpcmVzIjoxNzA1MjU3MDAyLjEyMjIxNDh9.MwOF8WhIwSbiiqVZ_q6J-HHZbyUavx1Di-I7_CtT-vQ' \
      -H 'Content-Type: application/json' \
      -d '{
      "id": 0,
      "title": "string",
      "content": "string"
    }'

About

FastAPI extension that provides JWT Auth support (secure, easy to use, and lightweight)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%