Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: grillazz/fastapi-sqlalchemy-asyncpg
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: SourceryAI/fastapi-sqlalchemy-asyncpg
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Oct 24, 2023

  1. 'Refactored by Sourcery'

    SourceryAI committed Oct 24, 2023
    Copy the full SHA
    46ac104 View commit details
Showing with 8 additions and 13 deletions.
  1. +1 −2 app/models/shakespeare.py
  2. +7 −11 app/services/auth.py
3 changes: 1 addition & 2 deletions app/models/shakespeare.py
Original file line number Diff line number Diff line change
@@ -133,5 +133,4 @@ class Paragraph(Base):
async def find(cls, db_session: AsyncSession, character: str):
stmt = select(cls).join(Character).join(Chapter).join(Work).where(Character.name == character)
result = await db_session.execute(stmt)
instance = result.scalars().all()
return instance
return result.scalars().all()
18 changes: 7 additions & 11 deletions app/services/auth.py
Original file line number Diff line number Diff line change
@@ -10,10 +10,7 @@

async def verify_jwt(request: Request, token: str) -> bool:
_payload = await request.app.state.redis.get(token)
if _payload:
return True
else:
return False
return bool(_payload)


class AuthBearer(HTTPBearer):
@@ -22,14 +19,13 @@ def __init__(self, auto_error: bool = True):

async def __call__(self, request: Request):
credentials: HTTPAuthorizationCredentials = await super().__call__(request)
if credentials:
if not credentials.scheme == "Bearer":
raise HTTPException(status_code=403, detail="Invalid authentication scheme.")
if not await verify_jwt(request, credentials.credentials):
raise HTTPException(status_code=403, detail="Invalid token or expired token.")
return credentials.credentials
else:
if not credentials:
raise HTTPException(status_code=403, detail="Invalid authorization code.")
if credentials.scheme != "Bearer":
raise HTTPException(status_code=403, detail="Invalid authentication scheme.")
if not await verify_jwt(request, credentials.credentials):
raise HTTPException(status_code=403, detail="Invalid token or expired token.")
return credentials.credentials


async def create_access_token(user: User, request: Request):