Skip to content

Commit

Permalink
🔨 JWT decoding error raises unauthorized exception
Browse files Browse the repository at this point in the history
  • Loading branch information
migduroli committed Jul 9, 2024
1 parent d22272f commit 085f209
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion flama/authentication/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def resolve(self, headers: Headers, cookies: Cookies) -> jwt.JWT:
token = jwt.JWT.decode(encoded_token, self.secret)
except (exceptions.JWTDecodeException, exceptions.JWTValidateException) as e:
raise HTTPException(
status_code=http.HTTPStatus.BAD_REQUEST, detail={"error": e.__class__, "description": str(e)}
status_code=http.HTTPStatus.UNAUTHORIZED, detail={"error": e.__class__, "description": str(e)}
)

return token
4 changes: 2 additions & 2 deletions tests/authentication/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ def jwt(token: JWT):
"n0sICJpYXQiOiAwfQ==.0000",
}
},
400,
401,
{
"detail": {
"description": "Signature verification failed for token 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVC"
"J9.eyJkYXRhIjogeyJmb28iOiAiYmFyIn0sICJpYXQiOiAwfQ==.0000'",
"error": "JWTValidateException",
},
"error": "HTTPException",
"status_code": 400,
"status_code": 401,
},
id="invalid_token",
),
Expand Down

0 comments on commit 085f209

Please sign in to comment.