Return UserInfo after validating the token's ``id_token``. The expected ``nonce`` is controlled by the application. Token claims such as ``nonce_supported`` cannot disable its validation.
(
self, token, nonce, claims_options=None, claims_cls=None, leeway=120
)
| 38 | return UserInfo(data) |
| 39 | |
| 40 | def parse_id_token( |
| 41 | self, token, nonce, claims_options=None, claims_cls=None, leeway=120 |
| 42 | ): |
| 43 | """Return UserInfo after validating the token's ``id_token``. |
| 44 | |
| 45 | The expected ``nonce`` is controlled by the application. Token claims |
| 46 | such as ``nonce_supported`` cannot disable its validation. |
| 47 | """ |
| 48 | if "id_token" not in token: |
| 49 | return None |
| 50 | |
| 51 | claims_params = dict( |
| 52 | nonce=nonce, |
| 53 | client_id=self.client_id, |
| 54 | ) |
| 55 | |
| 56 | if claims_cls is None: |
| 57 | if "access_token" in token: |
| 58 | claims_params["access_token"] = token["access_token"] |
| 59 | claims_cls = CodeIDToken |
| 60 | else: |
| 61 | claims_cls = ImplicitIDToken |
| 62 | |
| 63 | metadata = self.load_server_metadata() |
| 64 | if claims_options is None and "issuer" in metadata: |
| 65 | claims_options = {"iss": {"values": [metadata["issuer"]]}} |
| 66 | |
| 67 | alg_values = metadata.get("id_token_signing_alg_values_supported") |
| 68 | |
| 69 | key_set = KeySet.import_key_set(self.fetch_jwk_set()) |
| 70 | try: |
| 71 | token = jwt.decode( |
| 72 | token["id_token"], |
| 73 | key=key_set, |
| 74 | registry=JWSRegistry(algorithms=alg_values, strict_check_header=False), |
| 75 | ) |
| 76 | except InvalidKeyIdError: |
| 77 | key_set = KeySet.import_key_set(self.fetch_jwk_set(force=True)) |
| 78 | token = jwt.decode( |
| 79 | token["id_token"], |
| 80 | key=key_set, |
| 81 | registry=JWSRegistry(algorithms=alg_values, strict_check_header=False), |
| 82 | ) |
| 83 | |
| 84 | claims = claims_cls(token.claims, token.header, claims_options, claims_params) |
| 85 | claims.validate(leeway=leeway) |
| 86 | return UserInfo(claims) |
| 87 | |
| 88 | def create_logout_url( |
| 89 | self, |