Skip to content

Add JWT authentification support#5

Closed
armanddidierjean wants to merge 3 commits intomainfrom
authentification
Closed

Add JWT authentification support#5
armanddidierjean wants to merge 3 commits intomainfrom
authentification

Conversation

@armanddidierjean
Copy link
Member

@armanddidierjean armanddidierjean commented Apr 3, 2022

Add an endpoint to generate a JWT token, based on a password flow and Hyperion database
Add a dependency to check validity of the Bearer header

Usage

Install the new requirements

pip install -r requirements.txt
  1. Create a new user (currently without authentication)
curl --location --request POST 'http://127.0.0.1:8000/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "login": "jhobahtes",
    "password": "azerty",
    "name": "jhobahtes",
    "firstname": "jhobahtes",
    "nick": "jhobahtes",
    "birth": "01012000",
    "promo": "E",
    "floor": "A",
    "email": "jhobahtesemail",
    "created_on": 1
}'
  1. Get a JWT for this user
curl --location --request POST 'http://127.0.0.1:8000/auth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=jhobahtes' \
--data-urlencode 'password=azerty'
  1. Show existing users (Bearer authentication required, use the token you got during step 2)
curl --location --request GET 'http://127.0.0.1:8000/users/' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqaG9iYWh0ZXMiLCJleHAiOjE2NDkwMTcyNjF9.fSmvjIyxuchsVeVHCLyeTvmhcJGLjaOS07D5b2xBxW4'

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the documentation, if necessary


from app.database import SessionLocal

reusable_oauth2 = OAuth2PasswordBearer(tokenUrl="/auth/token")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you call the schema reusable ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def get_current_user(
db: Session = Depends(get_db), token: str = Depends(reusable_oauth2)
) -> models_users.CoreUser:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you comment this syntax ?

@armanddidierjean
Copy link
Member Author

Superseded by #8

@armanddidierjean armanddidierjean deleted the authentification branch December 1, 2022 08:07
Marc-Andrieu added a commit that referenced this pull request Jan 28, 2026
Marc-Andrieu added a commit that referenced this pull request Jan 28, 2026
Marc-Andrieu added a commit that referenced this pull request Jan 31, 2026
Marc-Andrieu added a commit that referenced this pull request Jan 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants