-
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.
- Loading branch information
Showing
6 changed files
with
131 additions
and
80 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
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
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
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 |
---|---|---|
|
@@ -3,5 +3,4 @@ | |
from .update import * | ||
from .remove import * | ||
from .verify import * | ||
from .access import * | ||
from .schemas import * |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
from jose import JWTError | ||
from login import * | ||
from fastapi import Depends, HTTPException | ||
from fastapi.security import OAuth2PasswordBearer | ||
from jose import JWTError, jwt | ||
|
||
SECRET_KEY = "project_worthy" | ||
ALGORITHM = "HS256" | ||
|
||
async def verify_token(token: str = Depends(OAuth2PasswordBearer(tokenUrl="token"))): | ||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/login") | ||
|
||
async def verify_token(token: str = Depends(oauth2_scheme)): | ||
try: | ||
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) | ||
username: str = payload.get("sub") | ||
if username is None: | ||
raise HTTPException(status_code=401, detail="Invalid token") | ||
return payload # payload를 반환하여 사용자 정보를 사용할 수 있도록 합니다. | ||
except JWTError: | ||
raise HTTPException(status_code=401, detail="Invalid token") | ||
return {"message": "Token is valid", "username": username} |