Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure/azure-pr-teardown-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

- bash: |
export AWS_PROFILE=apim-dev
cd mns_subscription
cd lambdas/mns_subscription

echo "unsubscribing SQS Queue from MNS notifications."
pyenv install -s 3.11.11
Expand Down
31 changes: 8 additions & 23 deletions lambdas/shared/src/common/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,13 @@ def create_jwt(self, now: int):
"exp": now + self.expiry,
"jti": str(uuid.uuid4())
}
logger.info(f"JWT claims: {claims}")
# ✅ Version-compatible JWT encoding
try:
# PyJWT 2.x
return jwt.encode(
claims,
secret_object['private_key'],
algorithm='RS512',
headers={"kid": secret_object['kid']}
)
except TypeError:
# PyJWT 1.x (older versions return bytes)
token = jwt.encode(
claims,
secret_object['private_key'],
algorithm='RS512',
headers={"kid": secret_object['kid']}
)
# Convert bytes to string if needed
return token.decode('utf-8') if isinstance(token, bytes) else token

return jwt.encode(
claims,
secret_object['private_key'],
algorithm='RS512',
headers={"kid": secret_object['kid']}
)

def get_access_token(self):
logger.info("get_access_token")
Expand All @@ -77,16 +64,14 @@ def get_access_token(self):
logger.info(f"Cache key: {self.cache_key}")
logger.info("Checking cache for access token")
cached = self.cache.get(self.cache_key)
logger.info(f"Cached token: {cached}")

if cached and cached["expires_at"] > now:
logger.info("Returning cached access token")
return cached["token"]

logger.info("No valid cached token found, creating new token")
_jwt = self.create_jwt(now)

logger.info(f"JWT created: {_jwt}")

headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
Expand Down
Loading