Skip to content

Commit 113c731

Browse files
committed
removed not null constraint on user field of the access token model
1 parent 267d415 commit 113c731

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

oauth2_provider/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class AccessToken(models.Model):
184184
:data:`settings.ACCESS_TOKEN_EXPIRE_SECONDS`
185185
* :attr:`scope` Allowed scopes
186186
"""
187-
user = models.ForeignKey(AUTH_USER_MODEL)
187+
user = models.ForeignKey(AUTH_USER_MODEL, blank=True, null=True)
188188
token = models.CharField(max_length=255, db_index=True)
189189
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
190190
expires = models.DateTimeField()

oauth2_provider/tests/test_models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.test import TestCase
1010
from django.test.utils import override_settings
1111
from django.core.exceptions import ValidationError
12+
from django.utils import timezone
1213

1314
from ..models import AccessToken, get_application_model, Grant, AccessToken, RefreshToken
1415
from ..compat import get_user_model
@@ -108,11 +109,24 @@ def test_str(self):
108109

109110

110111
class TestAccessTokenModel(TestCase):
112+
def setUp(self):
113+
self.user = UserModel.objects.create_user("test_user", "[email protected]", "123456")
111114

112115
def test_str(self):
113116
access_token = AccessToken(token="test_token")
114117
self.assertEqual("%s" % access_token, access_token.token)
115118

119+
def test_user_can_be_none(self):
120+
app = Application.objects.create(
121+
name="test_app",
122+
redirect_uris="http://localhost http://example.com http://example.it",
123+
user=self.user,
124+
client_type=Application.CLIENT_CONFIDENTIAL,
125+
authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE,
126+
)
127+
access_token = AccessToken.objects.create(token="test_token", application=app, expires=timezone.now())
128+
self.assertIsNone(access_token.user)
129+
116130

117131
class TestRefreshTokenModel(TestCase):
118132

0 commit comments

Comments
 (0)