-
-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from allisson/openid-connect
Add support for oidc connect discovery
- Loading branch information
Showing
11 changed files
with
153 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
# flake8: noqa | ||
from .base import AuthorizationView, TokenView, RevokeTokenView | ||
from .application import ApplicationRegistration, ApplicationDetail, ApplicationList, \ | ||
ApplicationDelete, ApplicationUpdate | ||
from .generic import ProtectedResourceView, ScopedProtectedResourceView, ReadWriteScopedResourceView | ||
from .token import AuthorizedTokensListView, AuthorizedTokenDeleteView | ||
from .application import ( | ||
ApplicationDelete, ApplicationDetail, ApplicationList, | ||
ApplicationRegistration, ApplicationUpdate | ||
) | ||
from .base import AuthorizationView, RevokeTokenView, TokenView | ||
from .generic import ( | ||
ProtectedResourceView, ReadWriteScopedResourceView, | ||
ScopedProtectedResourceView | ||
) | ||
from .introspect import IntrospectTokenView | ||
from .oidc import ConnectDiscoveryInfoView, JwksInfoView | ||
from .token import AuthorizedTokenDeleteView, AuthorizedTokensListView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import json | ||
|
||
from django.http import JsonResponse | ||
from django.urls import reverse_lazy | ||
from django.views.generic import View | ||
from jwcrypto import jwk | ||
|
||
from ..settings import oauth2_settings | ||
|
||
|
||
class ConnectDiscoveryInfoView(View): | ||
""" | ||
View used to show oidc provider configuration information | ||
""" | ||
def get(self, request, *args, **kwargs): | ||
issuer_url = oauth2_settings.OIDC_ISS_ENDPOINT | ||
data = { | ||
"issuer": issuer_url, | ||
"authorization_endpoint": "{}{}".format(issuer_url, reverse_lazy("oauth2_provider:authorize")), | ||
"token_endpoint": "{}{}".format(issuer_url, reverse_lazy("oauth2_provider:token")), | ||
"userinfo_endpoint": oauth2_settings.OIDC_USERINFO_ENDPOINT, | ||
"jwks_uri": "{}{}".format(issuer_url, reverse_lazy("oauth2_provider:jwks-info")), | ||
"response_types_supported": oauth2_settings.OIDC_RESPONSE_TYPES_SUPPORTED, | ||
"subject_types_supported": oauth2_settings.OIDC_SUBJECT_TYPES_SUPPORTED, | ||
"id_token_signing_alg_values_supported": oauth2_settings.OIDC_ID_TOKEN_SIGNING_ALG_VALUES_SUPPORTED, | ||
"token_endpoint_auth_methods_supported": oauth2_settings.OIDC_TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED, | ||
} | ||
response = JsonResponse(data) | ||
response["Access-Control-Allow-Origin"] = "*" | ||
return response | ||
|
||
|
||
class JwksInfoView(View): | ||
""" | ||
View used to show oidc json web key set document | ||
""" | ||
def get(self, request, *args, **kwargs): | ||
key = jwk.JWK.from_pem(oauth2_settings.OIDC_RSA_PRIVATE_KEY.encode("utf8")) | ||
data = { | ||
"keys": [{ | ||
"alg": "RS256", | ||
"use": "sig", | ||
"kid": key.thumbprint() | ||
}] | ||
} | ||
data["keys"][0].update(json.loads(key.export_public())) | ||
response = JsonResponse(data) | ||
response["Access-Control-Allow-Origin"] = "*" | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
|
||
class TestConnectDiscoveryInfoView(TestCase): | ||
def test_get_connect_discovery_info(self): | ||
expected_response = { | ||
"issuer": "http://localhost", | ||
"authorization_endpoint": "http://localhost/o/authorize/", | ||
"token_endpoint": "http://localhost/o/token/", | ||
"userinfo_endpoint": "http://localhost/userinfo/", | ||
"jwks_uri": "http://localhost/o/jwks/", | ||
"response_types_supported": [ | ||
"code", | ||
"token", | ||
"id_token", | ||
"id_token token", | ||
"code token", | ||
"code id_token", | ||
"code id_token token" | ||
], | ||
"subject_types_supported": ["public"], | ||
"id_token_signing_alg_values_supported": ["RS256", "HS256"], | ||
"token_endpoint_auth_methods_supported": ["client_secret_post", "client_secret_basic"] | ||
} | ||
response = self.client.get(reverse("oauth2_provider:oidc-connect-discovery-info")) | ||
self.assertEqual(response.status_code, 200) | ||
assert response.json() == expected_response | ||
|
||
|
||
class TestJwksInfoView(TestCase): | ||
def test_get_jwks_info(self): | ||
expected_response = { | ||
"keys": [{ | ||
"alg": "RS256", | ||
"use": "sig", | ||
"kid": "s4a1o8mFEd1tATAIH96caMlu4hOxzBUaI2QTqbYNBHs", | ||
"e": "AQAB", | ||
"kty": "RSA", | ||
"n": "mwmIeYdjZkLgalTuhvvwjvnB5vVQc7G9DHgOm20Hw524bLVTk49IXJ2Scw42HOmowWWX-oMVT_ca3ZvVIeffVSN1-TxVy2zB65s0wDMwhiMoPv35z9IKHGMZgl9vlyso_2b7daVF_FQDdgIayUn8TQylBxEU1RFfW0QSYOBdAt8" | ||
}] | ||
} | ||
response = self.client.get(reverse("oauth2_provider:jwks-info")) | ||
self.assertEqual(response.status_code, 200) | ||
assert response.json() == expected_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters