Skip to content

Commit

Permalink
sources/oauth: fix URLs being overwritten by OIDC urls (#8147)
Browse files Browse the repository at this point in the history
* sources/oauth: fix URLs being overwritten by OIDC urls

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix tests

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu authored Jan 13, 2024
1 parent d31c056 commit 98959a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 12 additions & 3 deletions authentik/sources/oauth/api/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def get_type(self, instance: OAuthSource) -> SourceTypeSerializer:
"""Get source's type configuration"""
return SourceTypeSerializer(instance.source_type).data

# pylint: disable=too-many-locals
def validate(self, attrs: dict) -> dict:
session = get_http_session()
source_type = registry.find_type(attrs["provider_type"])
Expand All @@ -73,9 +74,17 @@ def validate(self, attrs: dict) -> dict:
config = well_known_config.json()
if "issuer" not in config:
raise ValidationError({"oidc_well_known_url": "Invalid well-known configuration"})
attrs["authorization_url"] = config.get("authorization_endpoint", "")
attrs["access_token_url"] = config.get("token_endpoint", "")
attrs["profile_url"] = config.get("userinfo_endpoint", "")
field_map = {
# authentik field to oidc field
"authorization_url": "authorization_endpoint",
"access_token_url": "token_endpoint",
"profile_url": "userinfo_endpoint",
}
for ak_key, oidc_key in field_map.items():
# Don't overwrite user-set values
if ak_key in attrs and attrs[ak_key]:
continue

Check warning on line 86 in authentik/sources/oauth/api/source.py

View check run for this annotation

Codecov / codecov/patch

authentik/sources/oauth/api/source.py#L86

Added line #L86 was not covered by tests
attrs[ak_key] = config.get(oidc_key, "")
inferred_oidc_jwks_url = config.get("jwks_uri", "")

# Prefer user-entered URL to inferred URL to default URL
Expand Down
3 changes: 0 additions & 3 deletions authentik/sources/oauth/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ def test_api_validate_openid_connect(self):
"provider_type": "openidconnect",
"consumer_key": "foo",
"consumer_secret": "foo",
"authorization_url": "http://foo",
"access_token_url": "http://foo",
"profile_url": "http://foo",
"oidc_well_known_url": url,
"oidc_jwks_url": "",
},
Expand Down

0 comments on commit 98959a7

Please sign in to comment.