-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
following fastapi security to add oauth. wip
- Loading branch information
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import Depends | ||
from fastapi.security import OAuth2PasswordBearer | ||
from pydantic import BaseModel | ||
|
||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") | ||
|
||
|
||
class User(BaseModel): | ||
username: str | ||
email: str | None = None | ||
full_name: str | None = None | ||
disabled: bool | None = None | ||
|
||
|
||
def decode_token(token: str) -> User: | ||
return User( | ||
username="fakeuser", | ||
email="[email protected]", | ||
full_name="Fake User", | ||
) | ||
|
||
|
||
async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]) -> User: | ||
user = decode_token(token) | ||
return user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters