diff --git a/src/qgis_stac/api/base.py b/src/qgis_stac/api/base.py index 985b7af..e7aafe2 100644 --- a/src/qgis_stac/api/base.py +++ b/src/qgis_stac/api/base.py @@ -119,6 +119,7 @@ def get_items( api_capability=self.capability, response_handler=self.handle_items, error_handler=self.handle_error, + auth_config=self.auth_config, ) QgsApplication.taskManager().addTask(self.content_task) @@ -135,6 +136,7 @@ def get_collections( resource_type=ResourceType.COLLECTION, response_handler=self.handle_collections, error_handler=self.handle_error, + auth_config=self.auth_config, ) QgsApplication.taskManager().addTask(self.content_task) @@ -156,6 +158,7 @@ def get_collection( resource_type=ResourceType.COLLECTION, response_handler=self.handle_collection, error_handler=self.handle_error, + auth_config=self.auth_config, ) QgsApplication.taskManager().addTask(self.content_task) @@ -172,6 +175,7 @@ def get_conformance( resource_type=ResourceType.CONFORMANCE, response_handler=self.handle_conformance, error_handler=self.handle_error, + auth_config=self.auth_config, ) QgsApplication.taskManager().addTask(self.content_task) diff --git a/src/qgis_stac/api/network.py b/src/qgis_stac/api/network.py index 5014a23..bee868b 100644 --- a/src/qgis_stac/api/network.py +++ b/src/qgis_stac/api/network.py @@ -10,6 +10,7 @@ from qgis.core import ( QgsApplication, + QgsAuthMethodConfig, QgsNetworkContentFetcherTask, QgsTask, ) @@ -80,6 +81,7 @@ def __init__( api_capability: ApiCapability = None, response_handler: typing.Callable = None, error_handler: typing.Callable = None, + auth_config = None, ): super().__init__() self.url = url @@ -88,6 +90,7 @@ def __init__( self.api_capability = api_capability self.response_handler = response_handler self.error_handler = error_handler + self.auth_config = auth_config def run(self): """ @@ -96,8 +99,15 @@ def run(self): :returns: Whether the task completed successfully :rtype: bool """ + pystac_auth = {} + if self.auth_config: + auth_mgr = QgsApplication.authManager() + auth_cfg = QgsAuthMethodConfig() + auth_mgr.loadAuthenticationConfig(self.auth_config, auth_cfg, True) + if auth_cfg.method() == "APIHeader": + pystac_auth["headers"] = auth_cfg.configMap() try: - self.client = Client.open(self.url) + self.client = Client.open(self.url, **pystac_auth) if self.resource_type == \ ResourceType.FEATURE: if self.search_params: