🐛 Fix /auth/refresh
This commit is contained in:
parent
10681cc15b
commit
b50cbc4341
1 changed files with 7 additions and 3 deletions
|
|
@ -200,10 +200,14 @@ async def login(form_data: LoginRequest = Body(...)):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TokenRefresh(BaseModel):
|
||||||
|
refresh_token: str
|
||||||
|
|
||||||
|
|
||||||
@router.post("/refresh", response_model=AccessToken)
|
@router.post("/refresh", response_model=AccessToken)
|
||||||
async def refresh_token(refresh_token: str):
|
async def refresh_token(refresh_token: TokenRefresh = Body(...)):
|
||||||
"""Exchange refresh token for new access token."""
|
"""Exchange refresh token for new access token."""
|
||||||
payload = decode_token(refresh_token)
|
payload = decode_token(refresh_token.refresh_token)
|
||||||
if payload.get("type") != "refresh":
|
if payload.get("type") != "refresh":
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid refresh token"
|
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid refresh token"
|
||||||
|
|
@ -219,7 +223,7 @@ async def refresh_token(refresh_token: str):
|
||||||
new_access = create_token(
|
new_access = create_token(
|
||||||
claims(TokenType.access, user), ACCESS_TOKEN_EXPIRE_SECONDS
|
claims(TokenType.access, user), ACCESS_TOKEN_EXPIRE_SECONDS
|
||||||
)
|
)
|
||||||
return AccessToken(token_type="bearer", access_token=access_token)
|
return AccessToken(token_type="bearer", access_token=new_access)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/introspect", response_model=Dict[str, Any])
|
@router.get("/introspect", response_model=Dict[str, Any])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue