99from loguru import logger
1010from stac_pydantic import Collection
1111
12- from app .auth import exchange_token_for_provider
13- from app .config .settings import OpenEOAuthMethod , settings
12+ from app .auth import exchange_token
13+ from app .config .schemas import AuthMethod
14+ from app .config .settings import settings
1415from app .platforms .base import BaseProcessingPlatform
1516from app .platforms .dispatcher import register_platform
1617from app .schemas .enum import OutputFormatEnum , ProcessingStatusEnum , ProcessTypeEnum
@@ -58,28 +59,6 @@ def _connection_expired(self, connection: openeo.Connection) -> bool:
5859 logger .warning ("No JWT bearer token found in connection." )
5960 return True
6061
61- async def _get_bearer_token (self , user_token : str , url : str ) -> str :
62- """
63- Retrieve the bearer token for the OpenEO backend. This is done by exchanging the user's
64- token for a platform-specific token using the configured token provider.
65-
66- :param url: The URL of the OpenEO backend.
67- :return: The bearer token as a string.
68- """
69-
70- provider = settings .openeo_backend_config [url ].token_provider
71- token_prefix = settings .openeo_backend_config [url ].token_prefix
72-
73- if not provider or not token_prefix :
74- raise ValueError (
75- f"Backend '{ url } ' must define 'token_provider' and 'token_prefix'"
76- )
77-
78- platform_token = await exchange_token_for_provider (
79- initial_token = user_token , provider = provider
80- )
81- return f"{ token_prefix } /{ platform_token ['access_token' ]} "
82-
8362 async def _authenticate_user (
8463 self , user_token : str , url : str , connection : openeo .Connection
8564 ) -> openeo .Connection :
@@ -88,19 +67,19 @@ async def _authenticate_user(
8867 This method can be used to set the user's token for the connection.
8968 """
9069
91- if url not in settings .openeo_backend_config :
70+ if url not in settings .backend_auth_config :
9271 raise ValueError (f"No OpenEO backend configuration found for URL: { url } " )
9372
9473 if (
95- settings .openeo_backend_config [url ].auth_method
96- == OpenEOAuthMethod .USER_CREDENTIALS
74+ settings .backend_auth_config [url ].auth_method
75+ == AuthMethod .USER_CREDENTIALS
9776 ):
9877 logger .debug ("Using user credentials for OpenEO connection authentication" )
99- bearer_token = await self . _get_bearer_token (user_token , url )
78+ bearer_token = await exchange_token (user_token = user_token , url = url )
10079 connection .authenticate_bearer_token (bearer_token = bearer_token )
10180 elif (
102- settings .openeo_backend_config [url ].auth_method
103- == OpenEOAuthMethod .CLIENT_CREDENTIALS
81+ settings .backend_auth_config [url ].auth_method
82+ == AuthMethod .CLIENT_CREDENTIALS
10483 ):
10584 logger .debug (
10685 "Using client credentials for OpenEO connection authentication"
@@ -115,7 +94,7 @@ async def _authenticate_user(
11594 else :
11695 raise ValueError (
11796 "Unsupported OpenEO authentication method: "
118- f"{ settings .openeo_backend_config [url ].auth_method } "
97+ f"{ settings .backend_auth_config [url ].auth_method } "
11998 )
12099
121100 return connection
@@ -145,7 +124,7 @@ def _get_client_credentials(self, url: str) -> tuple[str, str, str]:
145124 :param url: The URL of the OpenEO backend.
146125 :return: A tuple containing provider ID, client ID, and client secret.
147126 """
148- credentials_str = settings .openeo_backend_config [url ].client_credentials
127+ credentials_str = settings .backend_auth_config [url ].client_credentials
149128
150129 if not credentials_str :
151130 raise ValueError (
0 commit comments