Skip to content

Commit 3bde632

Browse files
authored
Revert "Openid Connect Core support - Round 2 (#859)" (#877)
This reverts commit 4655c03.
1 parent 295c065 commit 3bde632

28 files changed

+259
-2897
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ __pycache__
2525
pip-log.txt
2626

2727
# Unit test / coverage reports
28-
.pytest_cache
28+
.cache
2929
.coverage
3030
.tox
3131
.pytest_cache/

oauth2_provider/admin.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .models import (
44
get_access_token_model, get_application_model,
5-
get_grant_model, get_id_token_model, get_refresh_token_model
5+
get_grant_model, get_refresh_token_model
66
)
77

88

@@ -26,11 +26,6 @@ class AccessTokenAdmin(admin.ModelAdmin):
2626
raw_id_fields = ("user", "source_refresh_token")
2727

2828

29-
class IDTokenAdmin(admin.ModelAdmin):
30-
list_display = ("token", "user", "application", "expires")
31-
raw_id_fields = ("user", )
32-
33-
3429
class RefreshTokenAdmin(admin.ModelAdmin):
3530
list_display = ("token", "user", "application")
3631
raw_id_fields = ("user", "access_token")
@@ -39,11 +34,9 @@ class RefreshTokenAdmin(admin.ModelAdmin):
3934
Application = get_application_model()
4035
Grant = get_grant_model()
4136
AccessToken = get_access_token_model()
42-
IDToken = get_id_token_model()
4337
RefreshToken = get_refresh_token_model()
4438

4539
admin.site.register(Application, ApplicationAdmin)
4640
admin.site.register(Grant, GrantAdmin)
4741
admin.site.register(AccessToken, AccessTokenAdmin)
48-
admin.site.register(IDToken, IDTokenAdmin)
4942
admin.site.register(RefreshToken, RefreshTokenAdmin)

oauth2_provider/forms.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class AllowForm(forms.Form):
55
allow = forms.BooleanField(required=False)
66
redirect_uri = forms.CharField(widget=forms.HiddenInput())
77
scope = forms.CharField(widget=forms.HiddenInput())
8-
nonce = forms.CharField(required=False, widget=forms.HiddenInput())
98
client_id = forms.CharField(widget=forms.HiddenInput())
109
state = forms.CharField(required=False, widget=forms.HiddenInput())
1110
response_type = forms.CharField(widget=forms.HiddenInput())

oauth2_provider/migrations/0002_auto_20190406_1805.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Generated by Django 2.2 on 2019-04-06 18:05
2+
13
from django.db import migrations, models
24

35

oauth2_provider/migrations/0003_auto_20200902_2022.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

oauth2_provider/models.py

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import logging
32
from datetime import timedelta
43
from urllib.parse import parse_qsl, urlparse
@@ -10,7 +9,6 @@
109
from django.urls import reverse
1110
from django.utils import timezone
1211
from django.utils.translation import gettext_lazy as _
13-
from jwcrypto import jwk, jwt
1412

1513
from .generators import generate_client_id, generate_client_secret
1614
from .scopes import get_scopes_backend
@@ -52,20 +50,11 @@ class AbstractApplication(models.Model):
5250
GRANT_IMPLICIT = "implicit"
5351
GRANT_PASSWORD = "password"
5452
GRANT_CLIENT_CREDENTIALS = "client-credentials"
55-
GRANT_OPENID_HYBRID = "openid-hybrid"
5653
GRANT_TYPES = (
5754
(GRANT_AUTHORIZATION_CODE, _("Authorization code")),
5855
(GRANT_IMPLICIT, _("Implicit")),
5956
(GRANT_PASSWORD, _("Resource owner password-based")),
6057
(GRANT_CLIENT_CREDENTIALS, _("Client credentials")),
61-
(GRANT_OPENID_HYBRID, _("OpenID connect hybrid")),
62-
)
63-
64-
RS256_ALGORITHM = "RS256"
65-
HS256_ALGORITHM = "HS256"
66-
ALGORITHM_TYPES = (
67-
(RS256_ALGORITHM, _("RSA with SHA-2 256")),
68-
(HS256_ALGORITHM, _("HMAC with SHA-2 256")),
6958
)
7059

7160
id = models.BigAutoField(primary_key=True)
@@ -93,7 +82,6 @@ class AbstractApplication(models.Model):
9382

9483
created = models.DateTimeField(auto_now_add=True)
9584
updated = models.DateTimeField(auto_now=True)
96-
algorithm = models.CharField(max_length=5, choices=ALGORITHM_TYPES, default=RS256_ALGORITHM)
9785

9886
class Meta:
9987
abstract = True
@@ -294,10 +282,6 @@ class AbstractAccessToken(models.Model):
294282
related_name="refreshed_access_token"
295283
)
296284
token = models.CharField(max_length=255, unique=True, )
297-
id_token = models.OneToOneField(
298-
oauth2_settings.ID_TOKEN_MODEL, on_delete=models.CASCADE, blank=True, null=True,
299-
related_name="access_token"
300-
)
301285
application = models.ForeignKey(
302286
oauth2_settings.APPLICATION_MODEL, on_delete=models.CASCADE, blank=True, null=True,
303287
)
@@ -431,99 +415,6 @@ class Meta(AbstractRefreshToken.Meta):
431415
swappable = "OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL"
432416

433417

434-
class AbstractIDToken(models.Model):
435-
"""
436-
An IDToken instance represents the actual token to
437-
access user's resources, as in :openid:`2`.
438-
439-
Fields:
440-
441-
* :attr:`user` The Django user representing resources' owner
442-
* :attr:`token` ID token
443-
* :attr:`application` Application instance
444-
* :attr:`expires` Date and time of token expiration, in DateTime format
445-
* :attr:`scope` Allowed scopes
446-
"""
447-
id = models.BigAutoField(primary_key=True)
448-
user = models.ForeignKey(
449-
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True,
450-
related_name="%(app_label)s_%(class)s"
451-
)
452-
token = models.TextField(unique=True)
453-
application = models.ForeignKey(
454-
oauth2_settings.APPLICATION_MODEL, on_delete=models.CASCADE, blank=True, null=True,
455-
)
456-
expires = models.DateTimeField()
457-
scope = models.TextField(blank=True)
458-
459-
created = models.DateTimeField(auto_now_add=True)
460-
updated = models.DateTimeField(auto_now=True)
461-
462-
def is_valid(self, scopes=None):
463-
"""
464-
Checks if the access token is valid.
465-
466-
:param scopes: An iterable containing the scopes to check or None
467-
"""
468-
return not self.is_expired() and self.allow_scopes(scopes)
469-
470-
def is_expired(self):
471-
"""
472-
Check token expiration with timezone awareness
473-
"""
474-
if not self.expires:
475-
return True
476-
477-
return timezone.now() >= self.expires
478-
479-
def allow_scopes(self, scopes):
480-
"""
481-
Check if the token allows the provided scopes
482-
483-
:param scopes: An iterable containing the scopes to check
484-
"""
485-
if not scopes:
486-
return True
487-
488-
provided_scopes = set(self.scope.split())
489-
resource_scopes = set(scopes)
490-
491-
return resource_scopes.issubset(provided_scopes)
492-
493-
def revoke(self):
494-
"""
495-
Convenience method to uniform tokens' interface, for now
496-
simply remove this token from the database in order to revoke it.
497-
"""
498-
self.delete()
499-
500-
@property
501-
def scopes(self):
502-
"""
503-
Returns a dictionary of allowed scope names (as keys) with their descriptions (as values)
504-
"""
505-
all_scopes = get_scopes_backend().get_all_scopes()
506-
token_scopes = self.scope.split()
507-
return {name: desc for name, desc in all_scopes.items() if name in token_scopes}
508-
509-
@property
510-
def claims(self):
511-
key = jwk.JWK.from_pem(oauth2_settings.OIDC_RSA_PRIVATE_KEY.encode("utf8"))
512-
jwt_token = jwt.JWT(key=key, jwt=self.token)
513-
return json.loads(jwt_token.claims)
514-
515-
def __str__(self):
516-
return self.token
517-
518-
class Meta:
519-
abstract = True
520-
521-
522-
class IDToken(AbstractIDToken):
523-
class Meta(AbstractIDToken.Meta):
524-
swappable = "OAUTH2_PROVIDER_ID_TOKEN_MODEL"
525-
526-
527418
def get_application_model():
528419
""" Return the Application model that is active in this project. """
529420
return apps.get_model(oauth2_settings.APPLICATION_MODEL)
@@ -539,11 +430,6 @@ def get_access_token_model():
539430
return apps.get_model(oauth2_settings.ACCESS_TOKEN_MODEL)
540431

541432

542-
def get_id_token_model():
543-
""" Return the AccessToken model that is active in this project. """
544-
return apps.get_model(oauth2_settings.ID_TOKEN_MODEL)
545-
546-
547433
def get_refresh_token_model():
548434
""" Return the RefreshToken model that is active in this project. """
549435
return apps.get_model(oauth2_settings.REFRESH_TOKEN_MODEL)

oauth2_provider/oauth2_backends.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,15 @@ def validate_authorization_request(self, request):
104104
except oauth2.OAuth2Error as error:
105105
raise OAuthToolkitError(error=error)
106106

107-
def create_authorization_response(self, uri, request, scopes, credentials, body, allow):
107+
def create_authorization_response(self, request, scopes, credentials, allow):
108108
"""
109109
A wrapper method that calls create_authorization_response on `server_class`
110110
instance.
111111
112112
:param request: The current django.http.HttpRequest object
113113
:param scopes: A list of provided scopes
114114
:param credentials: Authorization credentials dictionary containing
115-
`client_id`, `state`, `redirect_uri` and `response_type`
116-
:param body: Other body parameters not used in credentials dictionary
115+
`client_id`, `state`, `redirect_uri`, `response_type`
117116
:param allow: True if the user authorize the client, otherwise False
118117
"""
119118
try:
@@ -125,10 +124,10 @@ def create_authorization_response(self, uri, request, scopes, credentials, body,
125124
credentials["user"] = request.user
126125

127126
headers, body, status = self.server.create_authorization_response(
128-
uri=uri, scopes=scopes, credentials=credentials, body=body)
129-
redirect_uri = headers.get("Location", None)
127+
uri=credentials["redirect_uri"], scopes=scopes, credentials=credentials)
128+
uri = headers.get("Location", None)
130129

131-
return redirect_uri, headers, body, status
130+
return uri, headers, body, status
132131

133132
except oauth2.FatalClientError as error:
134133
raise FatalClientError(
@@ -167,21 +166,6 @@ def create_revocation_response(self, request):
167166

168167
return uri, headers, body, status
169168

170-
def create_userinfo_response(self, request):
171-
"""
172-
A wrapper method that calls create_userinfo_response on a
173-
`server_class` instance.
174-
175-
:param request: The current django.http.HttpRequest object
176-
"""
177-
uri, http_method, body, headers = self._extract_params(request)
178-
headers, body, status = self.server.create_userinfo_response(
179-
uri, http_method, body, headers
180-
)
181-
uri = headers.get("Location", None)
182-
183-
return uri, headers, body, status
184-
185169
def verify_request(self, request, scopes):
186170
"""
187171
A wrapper method that calls verify_request on `server_class` instance.

0 commit comments

Comments
 (0)