Skip to content

Commit 42a3160

Browse files
committed
Handle unsupported scheme exception
1 parent b780780 commit 42a3160

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

brood/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def create_user(
461461
if signature is not None:
462462
payload_json = base64.decodebytes(signature.encode()).decode("utf-8")
463463
payload = json.loads(payload_json)
464-
moonstream_schema: Any = MoonstreamRegistration # mypy hell
464+
moonstream_schema: Any = MoonstreamRegistration # mypy hell
465465
verified = verify(authorization_payload=payload, schema=moonstream_schema)
466466
if not verified:
467467
logger.info("Moonstream registration verification error")

brood/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async def create_user_handler(
162162
)
163163
except MoonstreamVerificationError:
164164
raise HTTPException(status_code=400, detail="Invalid user signature")
165-
except Exception as e:
165+
except Exception:
166166
raise HTTPException(status_code=500)
167167

168168
if autogenerated_user:

brood/middleware.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ async def get_current_user(
8585
if scheme == "moonstream":
8686
payload_json = base64.decodebytes(str(token).encode()).decode("utf-8")
8787
payload = json.loads(payload_json)
88-
moonstream_schema: Any = MoonstreamRegistration # mypy hell
89-
verified = verify(
90-
authorization_payload=payload, schema=moonstream_schema
91-
)
88+
moonstream_schema: Any = MoonstreamRegistration # mypy hell
89+
verified = verify(authorization_payload=payload, schema=moonstream_schema)
9290
if not verified:
9391
logger.info("Moonstream verification error")
9492
raise MoonstreamVerificationError()
@@ -106,8 +104,9 @@ async def get_current_user(
106104
if not is_token_active:
107105
raise actions.TokenNotActive("Access token not active")
108106
else:
109-
logger.error(f"Unaccepted authorization scheme {scheme}")
110-
raise Exception()
107+
raise HTTPException(
108+
status_code=401, detail="Unaccepted authorization scheme"
109+
)
111110

112111
except actions.TokenNotFound as e:
113112
logger.info(e)
@@ -160,10 +159,8 @@ async def get_current_user_with_groups(
160159
if scheme == "moonstream":
161160
payload_json = base64.decodebytes(str(token).encode()).decode("utf-8")
162161
payload = json.loads(payload_json)
163-
moonstream_schema: Any = MoonstreamRegistration # mypy hell
164-
verified = verify(
165-
authorization_payload=payload, schema=moonstream_schema
166-
)
162+
moonstream_schema: Any = MoonstreamRegistration # mypy hell
163+
verified = verify(authorization_payload=payload, schema=moonstream_schema)
167164
if not verified:
168165
logger.info("Moonstream authorization verification error")
169166
raise MoonstreamVerificationError()
@@ -186,8 +183,9 @@ async def get_current_user_with_groups(
186183
if not is_token_active:
187184
raise actions.TokenNotActive("Access token not active")
188185
else:
189-
logger.error(f"Unaccepted authorization scheme {scheme}")
190-
raise Exception()
186+
raise HTTPException(
187+
status_code=401, detail="Unaccepted authorization scheme"
188+
)
191189

192190
except actions.TokenNotFound as e:
193191
logger.info(e)

0 commit comments

Comments
 (0)