8000 updated · wpcodevo/python_fastapi@e381590 · GitHub
[go: up one dir, main page]

Skip to content

Commit e381590

Browse files
committed
updated
1 parent 2037f5c commit e381590

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

app/oauth2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1+
import base64
2+
from typing import List
13
from fastapi import Depends, HTTPException, status
24
from fastapi_jwt_auth import AuthJWT
5+
from pydantic import BaseModel
36

47
from . import models
58
from .database import get_db
69
from sqlalchemy.orm import Session
10+
from .config import settings
11+
12+
13+
class Settings(BaseModel):
14+
authjwt_algorithm: str = settings.JWT_ALGORITHM
15+
authjwt_decode_algorithms: List[str] = [settings.JWT_ALGORITHM]
16+
authjwt_token_location: set = {'cookies', 'headers'}
17+
authjwt_access_cookie_key: str = 'access_token'
18+
authjwt_refresh_cookie_key: str = 'refresh_token'
19+
authjwt_public_key: str = base64.b64decode(
20+
settings.JWT_PUBLIC_KEY).decode('utf-8')
21+
authjwt_private_key: str = base64.b64decode(
22+
settings.JWT_PRIVATE_KEY).decode('utf-8')
23+
24+
25+
@AuthJWT.load_config
26+
def get_config():
27+
return Settings()
728

829

930
class NotVerified(Exception):

app/routers/auth.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import base64
21
from datetime import timedelta
3-
from typing import List
42
from fastapi import APIRouter, Request, Response, status, Depends, HTTPException
5-
from pydantic import BaseModel, EmailStr
3+
from pydantic import EmailStr
64

75
from app import oauth2
86
from .. import schemas, models, utils
@@ -12,23 +10,6 @@
1210
from ..config import settings
1311

1412

15-
class Settings(BaseModel):
16-
authjwt_algorithm: str = settings.JWT_ALGORITHM
17-
authjwt_decode_algorithms: List[str] = [settings.JWT_ALGORITHM]
18-
authjwt_token_location: set = {'cookies', 'headers'}
19-
authjwt_access_cookie_key: str = 'access_token'
20-
authjwt_refresh_cookie_key: str = 'refresh_token'
21-
authjwt_public_key: str = base64.b64decode(
22-
settings.JWT_PUBLIC_KEY).decode('utf-8')
23-
authjwt_private_key: str = base64.b64decode(
24-
settings.JWT_PRIVATE_KEY).decode('utf-8')
25-
26-
27-
@AuthJWT.load_config
28-
def get_config():
29-
return Settings()
30-
31-
3213
router = APIRouter()
3314
ACCESS_TOKEN_EXPIRES_IN = settings.ACCESS_TOKEN_EXPIRES_IN
3415
REFRESH_TOKEN_EXPIRES_IN = settings.REFRESH_TOKEN_EXPIRES_IN

0 commit comments

Comments
 (0)
0