Skip to content

Commit

Permalink
Merge pull request #7 from jashwant/fix-minimal-refresh-token-endpoint
Browse files Browse the repository at this point in the history
removed duplicate refresh-token endpoint
  • Loading branch information
rafsaf authored Apr 14, 2022
2 parents 61be915 + 0a75877 commit 7357575
Showing 1 changed file with 0 additions and 41 deletions.
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,
}

0 comments on commit 7357575

Please sign in to comment.