Skip to content

Commit 38f5b4c

Browse files
committed
Issue #751 better error when .well-known/openid-configuration is down
1 parent 6b7c0d2 commit 38f5b4c

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- `sar_backscatter`: try to retrieve coefficient options from backend ([#693](https://github.com/Open-EO/openeo-python-client/issues/693))
13+
- Improve error message when OIDC provider is unavailable ([#751](https://github.com/Open-EO/openeo-python-client/issues/751))
1314

1415
### Changed
1516

openeo/rest/auth/oidc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,12 @@ def __init__(
268268
raise ValueError("At least `issuer` or `discovery_url` should be specified")
269269
if not requests_session:
270270
requests_session = requests.Session()
271-
discovery_resp = requests_session.get(self.discovery_url, timeout=20)
272-
discovery_resp.raise_for_status()
273-
self.config = discovery_resp.json()
271+
try:
272+
discovery_resp = requests_session.get(self.discovery_url, timeout=20)
273+
discovery_resp.raise_for_status()
274+
self.config = discovery_resp.json()
275+
except Exception as e:
276+
raise OidcException(f"Failed to obtain OIDC discovery document from {self.discovery_url!r}: {e!r}") from e
274277
self.issuer = issuer or self.config["issuer"]
275278
# Minimal set of scopes to request
276279
self._supported_scopes = self.config.get("scopes_supported", ["openid"])

tests/rest/auth/test_oidc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ def test_provider_info_get_scopes_string_refresh_token_offline_access(requests_m
238238
assert p.get_scopes_string() == "openid"
239239

240240

241+
def test_provider_info_issuer_broken_json(requests_mock):
242+
requests_mock.get("https://authit.test/.well-known/openid-configuration", text="<marquee>nope!</marquee>")
243+
with pytest.raises(
244+
OidcException,
245+
match="Failed to obtain OIDC discovery document from 'https://authit.test/.well-known/openid-configuration': JSONDecodeError",
246+
):
247+
OidcProviderInfo(issuer="https://authit.test")
248+
249+
241250
def test_oidc_client_info_uses_device_flow_pkce_support(requests_mock):
242251
oidc_issuer = "https://oidc.test"
243252
oidc_mock = OidcMock(

0 commit comments

Comments
 (0)