|
59 | 59 |
|
60 | 60 | logger = logging.getLogger(__name__) |
61 | 61 |
|
62 | | -# Methods `OAuthContext.prepare_token_auth` recognizes on a registered client, derived from the |
63 | | -# same set the SDK is willing to request so the two cannot drift. `None`/"none" send no client |
64 | | -# secret; `private_key_jwt` adds no secret here (its assertion is supplied by |
65 | | -# `PrivateKeyJWTOAuthProvider`). Anything else is a method this client cannot apply. |
66 | | -_RECOGNIZED_TOKEN_ENDPOINT_AUTH_METHODS: tuple[str | None, ...] = (None, *get_args(TokenEndpointAuthMethod)) |
| 62 | +# Methods a registered client's record may carry without a token request being an error, |
| 63 | +# derived from the set the SDK is willing to request so the two cannot drift. `None`/"none" |
| 64 | +# send no client secret; `private_key_jwt` sends none from here either, its assertion being |
| 65 | +# added by `PrivateKeyJWTOAuthProvider` (whose inherited refresh path passes through |
| 66 | +# `prepare_token_auth`). Anything else is a method no client here can apply. |
| 67 | +_KNOWN_TOKEN_ENDPOINT_AUTH_METHODS: tuple[str | None, ...] = (None, *get_args(TokenEndpointAuthMethod)) |
| 68 | + |
| 69 | +# Methods a registration completed by the authorization-code flow can act on. That flow |
| 70 | +# authenticates the token request with the minted client secret (or nothing); it holds no key |
| 71 | +# to sign a `private_key_jwt` assertion, so a server assigning that method has registered a |
| 72 | +# client this flow cannot use. `PrivateKeyJWTOAuthProvider` never registers dynamically. |
| 73 | +_REGISTRATION_USABLE_TOKEN_ENDPOINT_AUTH_METHODS: tuple[str | None, ...] = tuple( |
| 74 | + method for method in _KNOWN_TOKEN_ENDPOINT_AUTH_METHODS if method != "private_key_jwt" |
| 75 | +) |
67 | 76 |
|
68 | 77 |
|
69 | 78 | def check_registration_usable(client_info: OAuthClientInformationFull) -> None: |
70 | | - """Confirm a completed registration is one this client can act on. |
| 79 | + """Confirm a registration this flow completed is one it can act on. |
71 | 80 |
|
72 | 81 | RFC 7591 §3.2.1 lets the authorization server replace requested metadata and leaves it to |
73 | 82 | the client to "check the values in the response to determine if the registration is |
74 | 83 | sufficient for use". The one substitution that makes the minted credentials unusable is a |
75 | | - token-endpoint auth method this client cannot apply, so it is judged here - before the |
76 | | - record is persisted or any interactive authorization begins - rather than surfacing later |
77 | | - as an opaque failure at the token endpoint. |
| 84 | + token-endpoint auth method the authorization-code flow cannot apply - one it does not |
| 85 | + implement, or `private_key_jwt`, whose assertion this flow has no key to sign - so it is |
| 86 | + judged here, before the record is persisted or any interactive authorization begins, |
| 87 | + rather than surfacing later as an opaque failure at the token endpoint. |
78 | 88 |
|
79 | 89 | Raises: |
80 | 90 | OAuthRegistrationError: The server registered the client with a |
81 | | - `token_endpoint_auth_method` this client does not implement. |
| 91 | + `token_endpoint_auth_method` this flow cannot apply. |
82 | 92 | """ |
83 | | - if client_info.token_endpoint_auth_method not in _RECOGNIZED_TOKEN_ENDPOINT_AUTH_METHODS: |
| 93 | + if client_info.token_endpoint_auth_method not in _REGISTRATION_USABLE_TOKEN_ENDPOINT_AUTH_METHODS: |
84 | 94 | raise OAuthRegistrationError( |
85 | 95 | "Authorization server registered the client with unsupported token_endpoint_auth_method " |
86 | 96 | f"{client_info.token_endpoint_auth_method!r}" |
@@ -246,7 +256,7 @@ def prepare_token_auth( |
246 | 256 | # Include client_id and client_secret in request body (RFC 6749 §2.3.1) |
247 | 257 | data["client_id"] = self.client_info.client_id |
248 | 258 | data["client_secret"] = self.client_info.client_secret |
249 | | - elif auth_method not in _RECOGNIZED_TOKEN_ENDPOINT_AUTH_METHODS: |
| 259 | + elif auth_method not in _KNOWN_TOKEN_ENDPOINT_AUTH_METHODS: |
250 | 260 | raise OAuthTokenError(f"Registered client uses unsupported token_endpoint_auth_method {auth_method!r}") |
251 | 261 | # For "none" (or absent), don't add any client_secret; "private_key_jwt" adds its |
252 | 262 | # assertion in the provider that implements it, not here. |
|
0 commit comments