@@ -183,26 +183,34 @@ async def get_auth_credential(
183183 ) -> Optional [AuthCredential ]:
184184 """Load and prepare authentication credential through a structured workflow."""
185185
186- # Pydantic may have deserialized an unknown scheme into a generic
187- # CustomAuthScheme. If so, rehydrate it first into a specific subclass.
188- # Note: Custom authentication scheme classes must have been imported into
189- # the Python runtime before get_auth_credential is called for their
190- # subclasses to be registered. This is fine as developer will anyway import
191- # them while registering the auth providers.
192- # Note: `__subclasses__()` only returns immediate subclasses, if there is a
193- # subclass of a subclass of CustomAuthScheme then it will not be returned.
194- # pylint: disable=unidiomatic-typecheck Needs exact class matching.
195- if type (self ._auth_config .auth_scheme ) is CustomAuthScheme :
196- self ._auth_config .auth_scheme = _rehydrate_custom_scheme (
197- self ._auth_config .auth_scheme ,
198- CustomAuthScheme .__subclasses__ (),
186+ # Step 0: Handle CustomAuthScheme if present
187+ if isinstance (self ._auth_config .auth_scheme , CustomAuthScheme ):
188+ # Pydantic may have deserialized an unknown scheme into a generic
189+ # CustomAuthScheme. If so, rehydrate it first into a specific subclass.
190+ # Note: Custom authentication scheme classes must have been imported into
191+ # the Python runtime before get_auth_credential is called for their
192+ # subclasses to be registered. This is fine as developer will anyway
193+ # import them while registering the auth providers.
194+ # Note: `__subclasses__()` only returns immediate subclasses, if there is
195+ # a subclass of a subclass of CustomAuthScheme then it will not be
196+ # returned.
197+ # pylint: disable=unidiomatic-typecheck Needs exact class matching.
198+ if type (self ._auth_config .auth_scheme ) is CustomAuthScheme :
199+ self ._auth_config .auth_scheme = _rehydrate_custom_scheme (
200+ self ._auth_config .auth_scheme ,
201+ CustomAuthScheme .__subclasses__ (),
202+ )
203+
204+ provider = self ._auth_provider_registry .get_provider (
205+ self ._auth_config .auth_scheme
199206 )
200- # First, check if a registered auth provider is available before attempting
201- # to retrieve tokens natively.
202- provider = self ._auth_provider_registry .get_provider (
203- self ._auth_config .auth_scheme
204- )
205- if provider :
207+ if provider is None :
208+ raise ValueError (
209+ "No auth provider registered for custom auth scheme "
210+ f"{ self ._auth_config .auth_scheme .type_ !r} . "
211+ "Register it using `CredentialManager.register_auth_provider("
212+ "<YourAuthProviderInstance>)`."
213+ )
206214 provided_credential = await provider .get_auth_credential (
207215 self ._auth_config , context
208216 )
0 commit comments