Skip to content

Commit

Permalink
Merge branch 'main' into HIVE-1800-graphql-authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
siyoungbyun authored Jul 29, 2021
2 parents 9559123 + 606e2c0 commit f8aa2fa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Names and titles of core contributors (including people who did not push code to

```
* Logan Ripplinger (Software Engineer)
* Si Young Byun (Software Engineer)
```

## License
Expand Down
4 changes: 2 additions & 2 deletions bhjwt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from bhjwt.main import create_asserter
from bhjwt.main import create_asserter, PublicKeys
from bhjwt.assertions import AssertJwt
from bhjwt.exceptions import FailedToDecodeJwt, AuthorizationError
from bhjwt.config import AuthLibConfiguration
from bhjwt.providers import (
BrightHiveProvider,
OAuth2ProviderFactory,
OAuth2ProviderError,
)
from bhjwt.exceptions import AuthorizationError
from bhjwt.decorators.token_required_decorator import token_required
29 changes: 18 additions & 11 deletions bhjwt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ def _token_is_jwt(token: str) -> bool:


class PublicKeys:
@staticmethod
def get_public_keys():
return [
"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwejbXvlxa9CBQesoDMUd8Ih7wSn+1UQvkOJL/ueR0d0RZKGLGNSrOaDJDrn7Wexsee0Y4ANQty8l8HDHjsX1GDEt9ZfF7H1QW9QXi8THZOUESagTwZvNpofmB1yEin4ZmKbp80DY0RfZEnRWdvY4VW1KRZCiVgELgGXi4dACOJ8ZvhUfkfaeVcb5hjPbjnbjRhSMsF7IxwHpF0cccEAk+j5Ci8Cho1f5mfkMtYZc2Uugjs4C78wG/O2P2Qr1z3Fv1mapOpkvjJblD/+AJJVHIg/oQHzVpF0VdvDcv5y0g59eNV6pDNsPsrwaaZk10xzOhhVav9RiACEOaojk8nAIc9D4CKHjpyzz78vreCBMffZqf1Khl6LhzGIxYuOVXj/P6NgD7FTFDNTQ8CdETORqdirHkRSYE0yCnO3HvHnX8IpwCW9yWfCM6PBTLLCAxn4GxuJ+/5LkNahZJVlV9aR6BPweU+APTX11XlYig7WIJwUGeqOf6lhqT/w9pWr1utUf8t9wCSY/rNI1mHKAjPl+yYI+VL0VJ018RUQ0GRxcgLOnIdxTSBb2zewpwVV0KyD8BHPueiG6M4vbK1vk6f8Hzlyji3uWLqA+HTBBqGFZX6lAnESSCGJUj6zH0Gf0rTg9mduVtJDHGBONhXtq0JcS3/dqXLVVBfuL1ghs8eOWxm8CAwEAAQ==\n-----END PUBLIC KEY-----"
]
def __init__(self, public_keys: list = []):
if len(public_keys) > 0:
self._public_keys = public_keys
else:
self._public_keys = [
"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwejbXvlxa9CBQesoDMUd8Ih7wSn+1UQvkOJL/ueR0d0RZKGLGNSrOaDJDrn7Wexsee0Y4ANQty8l8HDHjsX1GDEt9ZfF7H1QW9QXi8THZOUESagTwZvNpofmB1yEin4ZmKbp80DY0RfZEnRWdvY4VW1KRZCiVgELgGXi4dACOJ8ZvhUfkfaeVcb5hjPbjnbjRhSMsF7IxwHpF0cccEAk+j5Ci8Cho1f5mfkMtYZc2Uugjs4C78wG/O2P2Qr1z3Fv1mapOpkvjJblD/+AJJVHIg/oQHzVpF0VdvDcv5y0g59eNV6pDNsPsrwaaZk10xzOhhVav9RiACEOaojk8nAIc9D4CKHjpyzz78vreCBMffZqf1Khl6LhzGIxYuOVXj/P6NgD7FTFDNTQ8CdETORqdirHkRSYE0yCnO3HvHnX8IpwCW9yWfCM6PBTLLCAxn4GxuJ+/5LkNahZJVlV9aR6BPweU+APTX11XlYig7WIJwUGeqOf6lhqT/w9pWr1utUf8t9wCSY/rNI1mHKAjPl+yYI+VL0VJ018RUQ0GRxcgLOnIdxTSBb2zewpwVV0KyD8BHPueiG6M4vbK1vk6f8Hzlyji3uWLqA+HTBBqGFZX6lAnESSCGJUj6zH0Gf0rTg9mduVtJDHGBONhXtq0JcS3/dqXLVVBfuL1ghs8eOWxm8CAwEAAQ==\n-----END PUBLIC KEY-----"
]

@property
def public_keys(self):
return self._public_keys


class BhJwtValidator(LegacyTokenMixin):
Expand All @@ -33,13 +39,14 @@ class BhJwtValidator(LegacyTokenMixin):
FailedToDecodeJwt?
"""

def __init__(self, token: str):
def __init__(self, token: str, public_keys: list = []):
BhJwtValidator._verify_not_legacy_access_token(token)
self.validated_claims = self._decode_jwt(token)
self.validated_claims = self._decode_jwt(token, public_keys)

@staticmethod
def _decode_jwt(encoded_jwt) -> dict:
for key in PublicKeys.get_public_keys():
def _decode_jwt(encoded_jwt, public_keys: list) -> dict:
public_keys = PublicKeys(public_keys)
for key in public_keys.public_keys:
try:
claims = jwt.decode(
encoded_jwt,
Expand Down Expand Up @@ -80,7 +87,7 @@ def _decode_jwt(encoded_jwt) -> dict:
)


def create_asserter(token: str) -> AssertJwt:
validated_claims = BhJwtValidator(token).validated_claims
def create_asserter(token: str, public_keys: list) -> AssertJwt:
validated_claims = BhJwtValidator(token, public_keys).validated_claims
asserter = AssertJwt(validated_claims)
return asserter
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="bhjwt",
version="0.0.4-alpha.5",
version="0.0.4-alpha.7",
author="Brighthive",
# author_email="[email protected]",
# description="Brighthive Library for JWT",
Expand Down

0 comments on commit f8aa2fa

Please sign in to comment.