Skip to content

Commit

Permalink
feat(token-cookie): web과 통합을 위한 token 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
Mincheol Kim committed Aug 2, 2020
1 parent 6f22c00 commit ec433bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/apps/oauth/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from http import HTTPStatus
from typing import Dict, Optional
from typing import Optional

from authlib.common.errors import AuthlibBaseError
from authlib.integrations.starlette_client import OAuth
Expand All @@ -9,7 +9,7 @@
from starlette.config import Config
from starlette.middleware.sessions import SessionMiddleware
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.responses import JSONResponse, RedirectResponse

from ...core.config import settings
from ...core.database import get_database_session
Expand Down Expand Up @@ -51,7 +51,7 @@ async def google_login(request: Request): # type: ignore
@oauth_client.get("/sign_in")
async def sign_in(
request: Request, session: Session = Depends(get_database_session)
) -> Dict[str, str]:
) -> RedirectResponse:
google_user_info = GoogleUserInfo.parse_obj(
await oauth.google.parse_id_token(
request, await oauth.google.authorize_access_token(request)
Expand All @@ -72,4 +72,6 @@ async def sign_in(
session.add(user)
session.commit()
app_token = create_access_token(google_user_info)
return {"token": app_token}
response = RedirectResponse(url=settings.WEB_URI)
response.set_cookie(key="token", value=app_token)
return response
1 change: 1 addition & 0 deletions src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Settings(BaseSettings):
PUBLIC_KEY: str = ""
JWT_ALGORITHM: str = "RS256"
SECRET_KEY: str = ""
WEB_URI: str = "https://checkhaebang.com/"

ACCESS_TOKEN_EXPIRE_SECONDS: int = 86400 * 7

Expand Down

0 comments on commit ec433bc

Please sign in to comment.