Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed duplicate refresh-token endpoint #7

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,44 +89,3 @@ async def refresh_token(
"refresh_token": refresh_token,
"refresh_expire_at": refresh_expire_at,
}


@router.post("/refresh-token", response_model=schemas.UserCreate)
async def refresh_token2(
input: schemas.TokenRefresh, session: AsyncSession = Depends(deps.get_session)
):
"""
OAuth2 compatible token, get an access token for future requests using refresh token
"""
try:
payload = jwt.decode(
input.refresh_token,
config.settings.SECRET_KEY,
algorithms=[security.ALGORITHM],
)
token_data = schemas.TokenPayload(**payload)
except (jwt.JWTError, ValidationError):
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Could not validate credentials",
)
if not token_data.refresh:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Could not validate credentials",
)
result = await session.execute(select(User).where(User.id == token_data.sub))
user: Optional[User] = result.scalars().first()

if user is None:
raise HTTPException(status_code=404, detail="User not found")

access_token, expire_at = security.create_access_token(user.id)
refresh_token, refresh_expire_at = security.create_refresh_token(user.id)
return {
"token_type": "bearer",
"access_token": access_token,
"expire_at": expire_at,
"refresh_token": refresh_token,
"refresh_expire_at": refresh_expire_at,
}