diff --git a/v2/microservice_auth/client-credentials.mdx b/v2/microservice_auth/client-credentials.mdx index 3f403b0f3..9af2981ad 100644 --- a/v2/microservice_auth/client-credentials.mdx +++ b/v2/microservice_auth/client-credentials.mdx @@ -350,11 +350,12 @@ func ValidateToken(token string) bool { You can use the [PyJWT](https://github.com/jpadilla/pyjwt) library to verify the token. ```python +from typing import Optional, List import requests import jwt from jwt import PyJWKClient -def validate_token(token): +def validate_token(token: str) -> bool: api_domain = "^{form_apiDomain}" api_base_path = "^{form_apiBasePath}" audience = "" @@ -364,7 +365,7 @@ def validate_token(token): jwks_client = PyJWKClient(jwks_url) try: - signing_key = jwks_client.get_signing_keys_from_jwt(token) + signing_key = jwks_client.get_signing_key_from_jwt(token) decoded = jwt.decode( token, signing_key.key, @@ -373,14 +374,13 @@ def validate_token(token): options={"require": ["stt", "scp"]} ) - sst = decoded.get('sst', None) + stt: Optional[int] = decoded.get('stt') if stt != 1: return False - - scopes = decoded.get('scp', []) - if required_scope not in scopes: - return False + scopes: List[str] = decoded.get('scp', []) + if not isinstance(scopes, list) or required_scope not in scopes: + return False return True except Exception as e: diff --git a/v2/unified-login/customizations/verify-tokens.mdx b/v2/unified-login/customizations/verify-tokens.mdx index 8ee1f38c0..30c4f9af7 100644 --- a/v2/unified-login/customizations/verify-tokens.mdx +++ b/v2/unified-login/customizations/verify-tokens.mdx @@ -157,11 +157,12 @@ func ValidateToken(token string) bool { You can use the [PyJWT](https://github.com/jpadilla/pyjwt) library to verify the token. ```python +from typing import Optional, List import requests import jwt from jwt import PyJWKClient -def validate_token(token): +def validate_token(token: str) -> bool: api_domain = "^{form_apiDomain}" api_base_path = "^{form_apiBasePath}" client_id = "" @@ -171,7 +172,7 @@ def validate_token(token): jwks_client = PyJWKClient(jwks_url) try: - signing_key = jwks_client.get_signing_keys_from_jwt(token) + signing_key = jwks_client.get_signing_key_from_jwt(token) decoded = jwt.decode( token, signing_key.key, @@ -180,17 +181,17 @@ def validate_token(token): options={"require": ["stt", "client_id", "scp"]} ) - sst = decoded.get('sst', None) + stt: Optional[int] = decoded.get('stt') if stt != 1: return False - token_client_id = decoded.get('client_id', None) + token_client_id: Optional[str] = decoded.get('client_id', None) if client_id != token_client_id: return False - scopes = decoded.get('scp', []) - if required_scope not in scopes: + scopes: List[str] = decoded.get('scp', []) + if not isinstance(scopes, list) or required_scope not in scopes: return False return True