-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from pseudolab/feature/login-system
social 로그인 관련 api
- Loading branch information
Showing
8 changed files
with
347 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import jwt | ||
from datetime import datetime, timedelta | ||
from typing import Union, Tuple | ||
|
||
SECRET_KEY = os.getenv("JWT_SECRET_KEY") | ||
ALGORITHM = "HS256" | ||
ACCESS_TOKEN_EXPIRE_MINUTES = 30 | ||
REFRESH_TOKEN_EXPIRE_DAYS = 7 | ||
|
||
|
||
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None) -> Tuple[str, datetime]: | ||
to_encode = data.copy() | ||
if expires_delta: | ||
expire = datetime.now() + expires_delta | ||
else: | ||
expire = datetime.now() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) | ||
to_encode.update({"exp": expire}) | ||
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) | ||
return encoded_jwt, expire | ||
|
||
|
||
def create_refresh_token(data: dict, expires_delta: Union[timedelta, None] = None) -> Tuple[str, datetime]: | ||
to_encode = data.copy() | ||
if expires_delta: | ||
expire = datetime.now() + expires_delta | ||
else: | ||
expire = datetime.now() + timedelta(days=REFRESH_TOKEN_EXPIRE_DAYS) | ||
to_encode.update({"exp": expire}) | ||
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) | ||
return encoded_jwt, expire |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.