Skip to content

Commit 9b66e29

Browse files
committed
Rename JWTIdentityError to InvalidAuthorizationScheme
1 parent e73eb60 commit 9b66e29

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

aiohttp_security/jwt_identity.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,20 @@
1111
try:
1212
import jwt
1313
HAS_JWT = True
14+
_bases_error = (jwt.exceptions.PyJWTError, ValueError)
1415
except ImportError: # pragma: no cover
1516
HAS_JWT = False
17+
_bases_error = (ValueError, )
1618

1719

1820
AUTH_HEADER_NAME = 'Authorization'
1921
AUTH_SCHEME = 'Bearer '
2022

2123

22-
if HAS_JWT:
23-
# This class inherits from ValueError to maintain backward compatibility
24-
# with previous versions of aiohttp-security.
25-
class JWTIdentityError(jwt.exceptions.PyJWTError, ValueError):
26-
pass
27-
28-
else:
29-
class JWTIdentityError(ValueError):
30-
pass
24+
# This class inherits from ValueError to maintain backward compatibility
25+
# with previous versions of aiohttp-security
26+
class InvalidAuthorizationScheme(*_bases_error):
27+
pass
3128

3229

3330
class JWTIdentityPolicy(AbstractIdentityPolicy):
@@ -45,15 +42,14 @@ async def identify(self, request: web.Request) -> Optional[str]:
4542
return None
4643

4744
if not header_identity.startswith(AUTH_SCHEME):
48-
raise JWTIdentityError("Invalid authorization scheme. "
49-
+ "Should be `{}<token>`".format(AUTH_SCHEME))
45+
raise InvalidAuthorizationScheme("Invalid authorization scheme. "
46+
"Should be `{}<token>`".format(AUTH_SCHEME))
5047

5148
token = header_identity.split(' ')[1].strip()
5249

5350
identity = jwt.decode(token,
5451
self.secret,
5552
algorithms=[self.algorithm])
56-
5753
return identity.get(self.key) # type: ignore[no-any-return]
5854

5955
async def remember(self, request: web.Request, response: web.StreamResponse,

0 commit comments

Comments
 (0)