Error when registering custom auth class
- Dominant language
- Python
- Stars
- 5.9k
- Forks
- 600
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 38
Description
### dlt version
1.6.0
### Describe the problem
Hi,
It seems the custom authentication registration is boken.
When I use, the CustomAuth like bellow, it works:
```
"auth": CustomAuth(
url=dlt.secrets["sources.eurecia.base_url"],
token=dlt.secrets["sources.eurecia.authorization"],
),
```
But when I try to register the same CustomAuth like this, I face a validation error :
```
register_auth("custom_auth", CustomAuth)
"auth": {
"type": "custom_auth",
"url": dlt.secrets["sources.eurecia.base_url"],
"token": dlt.secrets["sources.eurecia.authorization"],
},
```
> dlt.common.exceptions.DictValidationException: In path ./client: field 'auth' expects the following types: AuthConfigBase, Literal, BearerTokenAuth, BearerTokenAuthConfig, APIKeyAuth, ApiKeyAuthConfig, HttpBasicAuth, HttpBasicAuthConfig, OAuth2ClientCredentials, OAuth2ClientCredentialsConfig. Provided value {'type': 'custom_auth', 'url': 'https://api.eurecia.com/eurecia', 'token': 'o*****8'} with type 'dict' is invalid with the following errors:
> For BearerTokenAuthConfig: In path ./client/auth: following fields are unexpected {'url'}
> For ApiKeyAuthConfig: In path ./client/auth: following required fields are missing {'api_key'}
> For HttpBasicAuthConfig: In path ./client/auth: following required fields are missing {'username', 'password'}
> For OAuth2ClientCredentialsConfig: In path ./client/auth: following required fields are missing {'client_secret', 'client_id', 'access_token_url'}
> For AuthConfigBase: In path ./client: field 'auth' expects callable (function or class instance) but got '{'type': 'custom_auth', 'url': 'https://api.eurecia.com/eurecia', 'token': 'o*****8'}'. Mind that signatures are not validated
> For Literal: In path ./client: field 'auth' with value {'type': 'custom_auth', 'url': 'https://api.eurecia.com/eurecia', 'token': 'o*****8'} is not one of: ['bearer', 'api_key', 'http_basic', 'oauth2_client_credentials', 'custom_auth']
> For BearerTokenAuth: In path ./client: field 'auth' expects callable (function or class instance) but got '{'type': 'custom_auth', 'url': 'https://api.eurecia.com/eurecia', 'token': 'o*****8'}'. Mind that signatures are not validated
> For APIKeyAuth: In path ./client: field 'auth' expects callable (function or class instance) but got '{'type': 'custom_auth', 'url': 'https://api.eurecia.com/eurecia', 'token': 'o*****8'}'. Mind that signatures are not validated
> For HttpBasicAuth: In path ./client: field 'auth' expects callable (function or class instance) but got '{'type': 'custom_auth', 'url': 'https://api.eurecia.com/eurecia', 'token': 'o*****8'}'. Mind that signatures are not validated
> For OAuth2ClientCredentials: In path ./client: field 'auth' expects callable (function or class instance) but got '{'type': 'custom_auth', 'url': 'https://api.eurecia.com/eurecia', 'token': 'o*****8'}'. Mind that signatures are not validated
### Expected behavior
_No response_
### Steps to reproduce
Create a fake CustomAuth class that expects both a url and a token parameter.
Then try to register it. You may reproduce the error.
### Operating system
Windows
### Runtime environment
Local
### Python version
3.12
### dlt data source
_No response_
### dlt destination
_No response_
### Other deployment details
_No response_
### Additional information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.