Skip to content

Commit b4f418b

Browse files
dollarklavsJonas Nygaard Pedersen
andauthored
Fix double oauth2_provider mountpoint in oidc view (#957)
* Fix double oauth2_provider mountpoint in oidc view Fixes the doubling of mountpoint path in the OIDC endpoints values for `.well-known/openid-configuration/` * Updated tests According to the `django-oauth-toolkit` documentation for [OIDC_ISS_ENDPOINT](https://django-oauth-toolkit.readthedocs.io/en/latest/settings.html#oidc-iss-endpoint) this settings variable should enable discovery at `OIDC_ISS_ENDPOINT` + `/.well-known/openid-configuration/`. But if you use the variable as described you'll end up with the correct URL for the `issuer` value but incorrect URL's for the values of `authorization_endpoint`, `token_endpoint`, `userinfo_endpoint`, and `jwks_uri`. So if the `OIDC_ISS_ENDPOINT` is `http://localhost:8001/some-initial-path/o` the `issuer` will be `http://localhost:8001/some-initial-path/o` but `authorization_endpoint` will be `http://localhost:8001/some-initial-path/o/some-initial-path/o/authorize/`. Same pattern for `token_endpoint`, `userinfo_endpoint`, and `jwks_uri` This commit updates the tests to expect `OIDC_ISS_ENDPOINT` to end in `/o` * Updated AUTHORS * Update CHANGELOG * updated CHANGELOG To include possible breaking change message Co-authored-by: Jonas Nygaard Pedersen <[email protected]>
1 parent 27bd0af commit b4f418b

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Hiroki Kiyohara
3232
Jens Timmerman
3333
Jerome Leclanche
3434
Jim Graham
35+
Jonas Nygaard Pedersen
3536
Jonathan Steffan
3637
Jun Zhou
3738
Kristian Rune Larsen

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
### Added
2020
* #712, #636, #808. Calls to `django.contrib.auth.authenticate()` now pass a `request`
2121
to provide compatibility with backends that need one.
22-
22+
2323
### Fixed
2424
* #524 Restrict usage of timezone aware expire dates to Django projects with USE_TZ set to True.
25+
* #955 Avoid doubling of `oauth2_provider` urls mountpath in json response for OIDC view `ConnectDiscoveryInfoView`.
26+
Breaks existing OIDC discovery output
2527

2628
## [1.5.0] 2021-03-18
2729

oauth2_provider/views/oidc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from urllib.parse import urlparse
23

34
from django.http import HttpResponse, JsonResponse
45
from django.urls import reverse
@@ -32,12 +33,15 @@ def get(self, request, *args, **kwargs):
3233
)
3334
jwks_uri = request.build_absolute_uri(reverse("oauth2_provider:jwks-info"))
3435
else:
35-
authorization_endpoint = "{}{}".format(issuer_url, reverse("oauth2_provider:authorize"))
36-
token_endpoint = "{}{}".format(issuer_url, reverse("oauth2_provider:token"))
36+
parsed_url = urlparse(oauth2_settings.OIDC_ISS_ENDPOINT)
37+
host = parsed_url.scheme + "://" + parsed_url.netloc
38+
authorization_endpoint = "{}{}".format(host, reverse("oauth2_provider:authorize"))
39+
token_endpoint = "{}{}".format(host, reverse("oauth2_provider:token"))
3740
userinfo_endpoint = oauth2_settings.OIDC_USERINFO_ENDPOINT or "{}{}".format(
38-
issuer_url, reverse("oauth2_provider:user-info")
41+
host, reverse("oauth2_provider:user-info")
3942
)
40-
jwks_uri = "{}{}".format(issuer_url, reverse("oauth2_provider:jwks-info"))
43+
jwks_uri = "{}{}".format(host, reverse("oauth2_provider:jwks-info"))
44+
4145
signing_algorithms = [Application.HS256_ALGORITHM]
4246
if oauth2_settings.OIDC_RSA_PRIVATE_KEY:
4347
signing_algorithms = [Application.RS256_ALGORITHM, Application.HS256_ALGORITHM]

tests/presets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
DEFAULT_SCOPES_RO = {"DEFAULT_SCOPES": ["read"]}
1010
OIDC_SETTINGS_RW = {
1111
"OIDC_ENABLED": True,
12-
"OIDC_ISS_ENDPOINT": "http://localhost",
13-
"OIDC_USERINFO_ENDPOINT": "http://localhost/userinfo/",
12+
"OIDC_ISS_ENDPOINT": "http://localhost/o",
13+
"OIDC_USERINFO_ENDPOINT": "http://localhost/o/userinfo/",
1414
"OIDC_RSA_PRIVATE_KEY": settings.OIDC_RSA_PRIVATE_KEY,
1515
"SCOPES": {
1616
"read": "Reading scope",

tests/test_oidc_views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
class TestConnectDiscoveryInfoView(TestCase):
1313
def test_get_connect_discovery_info(self):
1414
expected_response = {
15-
"issuer": "http://localhost",
15+
"issuer": "http://localhost/o",
1616
"authorization_endpoint": "http://localhost/o/authorize/",
1717
"token_endpoint": "http://localhost/o/token/",
18-
"userinfo_endpoint": "http://localhost/userinfo/",
18+
"userinfo_endpoint": "http://localhost/o/userinfo/",
1919
"jwks_uri": "http://localhost/o/.well-known/jwks.json",
2020
"response_types_supported": [
2121
"code",

0 commit comments

Comments
 (0)