Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

Commit bd14522

Browse files
faysal-ishtiaqisedwards
authored andcommitted
fix oauth scheme for climsoft
1 parent 2523ded commit bd14522

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ services:
8888
- HOST_FQDN=$HOST_FQDN
8989
- CLIMSOFT_AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
9090
- CLIMSOFT_AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
91-
- AUTH_ENABLED=false
91+
- AUTH_ENABLED=true
9292
depends_on:
9393
- opencdms_surfacedb
9494
volumes:

src/opencdms_api/middleware.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020

2121
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth")
22+
climsoft_oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/climsoft-auth")
2223

2324

2425
def get_user(username: str) -> Optional[CurrentUserSchema]:
@@ -142,7 +143,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send):
142143

143144
def get_authorized_climsoft_user(
144145
request: Request,
145-
token: str = Depends(oauth2_scheme)
146+
token: str = Depends(climsoft_oauth2_scheme)
146147
):
147148
try:
148149
claims = jwt.decode(token, settings.SURFACE_SECRET_KEY)

src/opencdms_api/router.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ def authenticate(
6969
return TokenSchema(access_token=access_token, first_name=user.first_name, last_name=user.last_name)
7070

7171

72-
@router.post("/climsoft-auth", response_model=TokenSchema)
72+
@router.post("/climsoft-auth", response_model=ClimsoftTokenSchema)
7373
def authenticate(
7474
payload: OAuth2PasswordRequestForm = Depends(),
75-
session: Session = Depends(deps.get_climsoft_session())
75+
session: Session = Depends(deps.get_climsoft_session)
7676
):
7777
user = session.execute(sa_text(f'''
7878
SELECT User
@@ -87,13 +87,12 @@ def authenticate(
8787

8888
access_token = jwt.encode(
8989
{
90-
"sub": user[1],
90+
"sub": user['User'],
9191
"exp": datetime.utcnow() + timedelta(hours=24),
9292
"token_type": "access",
93-
"jti": str(uuid4()),
94-
"user_id": int(user.id)
93+
"jti": str(uuid4())
9594
},
9695
key=settings.SURFACE_SECRET_KEY,
9796
)
98-
return ClimsoftTokenSchema(access_token=access_token, username=user[1])
97+
return ClimsoftTokenSchema(access_token=access_token, username=user['User'])
9998

0 commit comments

Comments
 (0)