diff --git a/oauth2_provider/migrations/0005_auto_20170514_1141.py b/oauth2_provider/migrations/0005_auto_20170514_1141.py index 0a64daeed..4eca6c863 100644 --- a/oauth2_provider/migrations/0005_auto_20170514_1141.py +++ b/oauth2_provider/migrations/0005_auto_20170514_1141.py @@ -55,4 +55,48 @@ class Migration(migrations.Migration): name='user', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='oauth2_provider_refreshtoken', to=settings.AUTH_USER_MODEL), ), + migrations.AddField( + model_name='accesstoken', + name='created', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='accesstoken', + name='updated', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='application', + name='created', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='application', + name='updated', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='grant', + name='created', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='grant', + name='updated', + field=models.DateTimeField(auto_now=True), + ), + migrations.AddField( + model_name='refreshtoken', + name='created', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='refreshtoken', + name='updated', + field=models.DateTimeField(auto_now=True), + ), ] diff --git a/oauth2_provider/models.py b/oauth2_provider/models.py index ed0ee457c..b2967c7c1 100644 --- a/oauth2_provider/models.py +++ b/oauth2_provider/models.py @@ -81,6 +81,9 @@ class AbstractApplication(models.Model): name = models.CharField(max_length=255, blank=True) skip_authorization = models.BooleanField(default=False) + created = models.DateTimeField(auto_now_add=True) + updated = models.DateTimeField(auto_now=True) + class Meta: abstract = True @@ -182,6 +185,9 @@ class AbstractGrant(models.Model): redirect_uri = models.CharField(max_length=255) scope = models.TextField(blank=True) + created = models.DateTimeField(auto_now_add=True) + updated = models.DateTimeField(auto_now=True) + def is_expired(self): """ Check token expiration with timezone awareness @@ -232,6 +238,9 @@ class AbstractAccessToken(models.Model): expires = models.DateTimeField() scope = models.TextField(blank=True) + created = models.DateTimeField(auto_now_add=True) + updated = models.DateTimeField(auto_now=True) + def is_valid(self, scopes=None): """ Checks if the access token is valid. @@ -318,6 +327,9 @@ class AbstractRefreshToken(models.Model): related_name="refresh_token" ) + created = models.DateTimeField(auto_now_add=True) + updated = models.DateTimeField(auto_now=True) + def revoke(self): """ Delete this refresh token along with related access token