Skip to content

Commit

Permalink
Merge pull request #16 from hotosm/auth
Browse files Browse the repository at this point in the history
Endpoint to access refresh token
  • Loading branch information
nrjadkry authored Jul 1, 2024
2 parents 7e0acd6 + 5ec8cef commit b550acb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/backend/app/users/oauth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from app.db import database
from app.users.user_routes import router
from app.users.user_deps import init_google_auth, login_required
from app.users.user_schemas import AuthUser
from app.users.user_schemas import AuthUser, Token
from app.users import user_crud
from app.config import settings

Expand Down Expand Up @@ -45,7 +45,15 @@ async def callback(request: Request, google_auth=Depends(init_google_auth)):
user_data = google_auth.deserialize_access_token(access_token)
access_token, refresh_token = user_crud.create_access_token(user_data)

return {"access_token": access_token, "refresh_token": refresh_token}
return Token(access_token=access_token, refresh_token=refresh_token)


@router.get("/refresh-token", response_model=Token)
def update_token(user_data: AuthUser = Depends(login_required)):
"""Refresh access token"""

access_token, refresh_token = user_crud.create_access_token(user_data.model_dump())
return Token(access_token=access_token, refresh_token=refresh_token)


@router.get("/my-info/")
Expand Down
4 changes: 3 additions & 1 deletion src/backend/app/users/user_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def login_access_token(
elif not user.is_active:
raise HTTPException(status_code=400, detail="Inactive user")

access_token, refresh_token = user_crud.create_access_token(user.id)
user_info = {"id": user.id, "email": user.email_address}

access_token, refresh_token = user_crud.create_access_token(user_info)

return Token(access_token=access_token, refresh_token=refresh_token)

Expand Down

0 comments on commit b550acb

Please sign in to comment.