Skip to content

Commit 7357575

Browse files
authored
Merge pull request #7 from jashwant/fix-minimal-refresh-token-endpoint
removed duplicate refresh-token endpoint
2 parents 61be915 + 0a75877 commit 7357575

File tree

1 file changed

+0
-41
lines changed
  • {{cookiecutter.project_name}}/template_minimal/app/api/endpoints

1 file changed

+0
-41
lines changed

{{cookiecutter.project_name}}/template_minimal/app/api/endpoints/auth.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -89,44 +89,3 @@ async def refresh_token(
8989
"refresh_token": refresh_token,
9090
"refresh_expire_at": refresh_expire_at,
9191
}
92-
93-
94-
@router.post("/refresh-token", response_model=schemas.UserCreate)
95-
async def refresh_token2(
96-
input: schemas.TokenRefresh, session: AsyncSession = Depends(deps.get_session)
97-
):
98-
"""
99-
OAuth2 compatible token, get an access token for future requests using refresh token
100-
"""
101-
try:
102-
payload = jwt.decode(
103-
input.refresh_token,
104-
config.settings.SECRET_KEY,
105-
algorithms=[security.ALGORITHM],
106-
)
107-
token_data = schemas.TokenPayload(**payload)
108-
except (jwt.JWTError, ValidationError):
109-
raise HTTPException(
110-
status_code=status.HTTP_403_FORBIDDEN,
111-
detail="Could not validate credentials",
112-
)
113-
if not token_data.refresh:
114-
raise HTTPException(
115-
status_code=status.HTTP_403_FORBIDDEN,
116-
detail="Could not validate credentials",
117-
)
118-
result = await session.execute(select(User).where(User.id == token_data.sub))
119-
user: Optional[User] = result.scalars().first()
120-
121-
if user is None:
122-
raise HTTPException(status_code=404, detail="User not found")
123-
124-
access_token, expire_at = security.create_access_token(user.id)
125-
refresh_token, refresh_expire_at = security.create_refresh_token(user.id)
126-
return {
127-
"token_type": "bearer",
128-
"access_token": access_token,
129-
"expire_at": expire_at,
130-
"refresh_token": refresh_token,
131-
"refresh_expire_at": refresh_expire_at,
132-
}

0 commit comments

Comments
 (0)