Skip to content

Commit 77c9208

Browse files
committed
Added correct meta flag to AbstractAccessToken and AbstractRefreshToken
1 parent 6a8b1fa commit 77c9208

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

oauth2_provider/models.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,14 @@ def __str__(self):
166166

167167
@python_2_unicode_compatible
168168
class AbstractAccessToken(models.Model):
169-
"""
170-
An AccessToken instance represents the actual access token to
171-
access user's resources, as in :rfc:`5`.
172-
173-
Fields:
174-
175-
* :attr:`user` The Django user representing resources' owner
176-
* :attr:`token` Access token
177-
* :attr:`application` Application instance
178-
* :attr:`expires` Expire time in seconds, defaults to
179-
:data:`settings.ACCESS_TOKEN_EXPIRE_SECONDS`
180-
* :attr:`scope` Allowed scopes
181-
"""
182169
user = models.ForeignKey(AUTH_USER_MODEL, blank=True, null=True)
183-
token = models.CharField(max_length=255, db_index=True)
184170
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
185171
expires = models.DateTimeField()
186172
scope = models.TextField(blank=True)
187173

174+
class Meta:
175+
abstract = True
176+
188177
def is_valid(self, scopes=None):
189178
"""
190179
Checks if the access token is valid.
@@ -218,14 +207,40 @@ def __str__(self):
218207

219208

220209
class AccessToken(AbstractAccessToken):
221-
pass
210+
"""
211+
An AccessToken instance represents the actual access token to
212+
access user's resources, as in :rfc:`5`.
213+
214+
Fields:
215+
216+
* :attr:`user` The Django user representing resources' owner
217+
* :attr:`token` Access token
218+
* :attr:`application` Application instance
219+
* :attr:`expires` Expire time in seconds, defaults to
220+
:data:`settings.ACCESS_TOKEN_EXPIRE_SECONDS`
221+
* :attr:`scope` Allowed scopes
222+
"""
223+
token = models.CharField(max_length=255, db_index=True)
222224

223225
# Add swappable like this to not break django 1.4 compatibility
224226
AccessToken._meta.swappable = 'OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL'
225227

226228

227229
@python_2_unicode_compatible
228230
class AbstractRefreshToken(models.Model):
231+
user = models.ForeignKey(AUTH_USER_MODEL)
232+
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
233+
access_token = models.OneToOneField(oauth2_settings.ACCESS_TOKEN_MODEL,
234+
related_name='refresh_token')
235+
236+
class Meta:
237+
abstract = True
238+
239+
def __str__(self):
240+
return self.token
241+
242+
243+
class RefreshToken(AbstractRefreshToken):
229244
"""
230245
A RefreshToken instance represents a token that can be swapped for a new
231246
access token when it expires.
@@ -238,18 +253,7 @@ class AbstractRefreshToken(models.Model):
238253
* :attr:`access_token` AccessToken instance this refresh token is
239254
bounded to
240255
"""
241-
user = models.ForeignKey(AUTH_USER_MODEL)
242256
token = models.CharField(max_length=255, db_index=True)
243-
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL)
244-
access_token = models.OneToOneField(oauth2_settings.ACCESS_TOKEN_MODEL,
245-
related_name='refresh_token')
246-
247-
def __str__(self):
248-
return self.token
249-
250-
251-
class RefreshToken(AbstractRefreshToken):
252-
pass
253257

254258
# Add swappable like this to not break django 1.4 compatibility
255259
RefreshToken._meta.swappable = 'OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL'

0 commit comments

Comments
 (0)