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

Skip to content

Commit 3e7a63a

Browse files
committed
updated
1 parent e381590 commit 3e7a63a

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

app/models.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import uuid
12
from .database import Base
23
from sqlalchemy import TIMESTAMP, Column, String, Boolean, text
34
from sqlalchemy.dialects.postgresql import UUID
45

56

67
class User(Base):
78
__tablename__ = 'users'
8-
id = Column(UUID, primary_key=True, nullable=False,
9-
server_default=text("uuid_generate_v4()"))
9+
id = Column(UUID(as_uuid=True), primary_key=True, nullable=False,
10+
default=uuid.uuid4)
1011
name = Column(String, nullable=False)
1112
email = Column(String, unique=True, nullable=False)
1213
password = Column(String, nullable=False)

app/oauth2.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Settings(BaseModel):
1616
authjwt_token_location: set = {'cookies', 'headers'}
1717
authjwt_access_cookie_key: str = 'access_token'
1818
authjwt_refresh_cookie_key: str = 'refresh_token'
19+
authjwt_cookie_csrf_protect: bool = False
1920
authjwt_public_key: str = base64.b64decode(
2021
settings.JWT_PUBLIC_KEY).decode('utf-8')
2122
authjwt_private_key: str = base64.b64decode(

app/routers/auth.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def login(payload: schemas.LoginUserSchema, response: Response, db: Session = De
6161

6262
# Create access token
6363
access_token = Authorize.create_access_token(
64-
subject=user.id, expires_time=timedelta(minutes=ACCESS_TOKEN_EXPIRES_IN))
64+
subject=str(user.id), expires_time=timedelta(minutes=ACCESS_TOKEN_EXPIRES_IN))
6565

6666
# Create refresh token
6767
refresh_token = Authorize.create_refresh_token(
68-
subject=user.id, expires_time=timedelta(minutes=REFRESH_TOKEN_EXPIRES_IN))
68+
subject=str(user.id), expires_time=timedelta(minutes=REFRESH_TOKEN_EXPIRES_IN))
6969

7070
# Store refresh and access tokens in cookie
7171
response.set_cookie('access_token', access_token, ACCESS_TOKEN_EXPIRES_IN * 60,
@@ -94,7 +94,7 @@ def refresh_token(response: Response, request: Request, Authorize: AuthJWT = Dep
9494
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED,
9595
detail='The user belonging to this token no logger exist')
9696
access_token = Authorize.create_access_token(
97-
subject=user_id, expires_time=timedelta(minutes=ACCESS_TOKEN_EXPIRES_IN))
97+
subject=str(user.id), expires_time=timedelta(minutes=ACCESS_TOKEN_EXPIRES_IN))
9898
except Exception as e:
9999
error = e.__class__.__name__
100100
if error == 'MissingTokenError':

app/schemas.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
import uuid
23
from pydantic import BaseModel, EmailStr, constr
34

45

@@ -24,6 +25,6 @@ class LoginUserSchema(BaseModel):
2425

2526

2627
class UserResponse(UserBaseSchema):
27-
id: str
28+
id: uuid.UUID
2829
created_at: datetime
2930
updated_at: datetime

0 commit comments

Comments
 (0)
0