Auth
cdse.auth.OAuth2Auth
OAuth2 authentication handler for CDSE.
This class manages OAuth2 client credentials authentication for the Copernicus Data Space Ecosystem.
Attributes:
| Name | Type | Description |
|---|---|---|
TOKEN_URL |
CDSE OAuth2 token endpoint |
Example
auth = OAuth2Auth("client_id", "client_secret") session = auth.get_session()
Use session for API requests
__init__(client_id: Optional[str] = None, client_secret: Optional[str] = None)
Initialize OAuth2 authentication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client_id
|
Optional[str]
|
OAuth2 client ID. If not provided, reads from CDSE_CLIENT_ID environment variable. |
None
|
client_secret
|
Optional[str]
|
OAuth2 client secret. If not provided, reads from CDSE_CLIENT_SECRET environment variable. |
None
|
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If credentials are not provided or invalid. |
get_session() -> OAuth2Session
Get an authenticated OAuth2 session.
Returns:
| Type | Description |
|---|---|
OAuth2Session
|
Authenticated OAuth2Session ready for API requests. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If authentication fails. |
get_access_token() -> str
Get the current access token.
Returns:
| Type | Description |
|---|---|
str
|
The OAuth2 access token string. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If no valid token available. |
is_valid() -> bool
Check if the current token is valid.
Returns:
| Type | Description |
|---|---|
bool
|
True if token exists and is not expired, False otherwise. |
refresh() -> None
Refresh the authentication token.
Forces re-authentication to get a new token.
get_bearer_session() -> requests.Session
Get a standard requests Session with Bearer token.
Useful for APIs that don't support OAuth2Session directly.
Returns:
| Type | Description |
|---|---|
Session
|
requests.Session with Authorization header set. |