1
1
# -*- coding: utf-8 -*-
2
- import datetime
3
- from south .db import db
4
- from south .v2 import SchemaMigration
5
- from django .db import models
6
-
7
- try :
8
- from django .contrib .auth import get_user_model
9
- except ImportError : # django < 1.5
10
- from django .contrib .auth .models import User
11
- else :
12
- User = get_user_model ()
13
-
14
- from oauth2_provider .models import get_application_model
15
- ApplicationModel = get_application_model ()
16
-
17
-
18
- class Migration (SchemaMigration ):
19
-
20
- def forwards (self , orm ):
21
- # Adding model 'Application'
22
- db .create_table (u'oauth2_provider_application' , (
23
- (u'id' , self .gf ('django.db.models.fields.AutoField' )(primary_key = True )),
24
- ('client_id' , self .gf ('django.db.models.fields.CharField' )(default = '284250a821f74df67cb50b6c2b7fc95d39d0e4a9' , unique = True , max_length = 100 )),
25
- ('user' , self .gf ('django.db.models.fields.related.ForeignKey' )(to = orm ["%s.%s" % (User ._meta .app_label , User ._meta .object_name )])),
26
- ('redirect_uris' , self .gf ('django.db.models.fields.TextField' )(blank = True )),
27
- ('client_type' , self .gf ('django.db.models.fields.CharField' )(max_length = 32 )),
28
- ('authorization_grant_type' , self .gf ('django.db.models.fields.CharField' )(max_length = 32 )),
29
- ('client_secret' , self .gf ('django.db.models.fields.CharField' )(default = '89288b8343edef095b5fee98b4def28409cf4e064fcd26b00c555f51d8fdabfcaedbae8b9d6739080cf27d216e13cc85133d794c9cc1018e0d116c951f0b865e' , max_length = 255 , blank = True )),
30
- ('name' , self .gf ('django.db.models.fields.CharField' )(max_length = 255 , blank = True )),
31
- ))
32
- db .send_create_signal (u'oauth2_provider' , ['Application' ])
33
-
34
- # Adding model 'Grant'
35
- db .create_table (u'oauth2_provider_grant' , (
36
- (u'id' , self .gf ('django.db.models.fields.AutoField' )(primary_key = True )),
37
- ('user' , self .gf ('django.db.models.fields.related.ForeignKey' )(to = orm ["%s.%s" % (User ._meta .app_label , User ._meta .object_name )])),
38
- ('code' , self .gf ('django.db.models.fields.CharField' )(max_length = 255 )),
39
- ('application' , self .gf ('django.db.models.fields.related.ForeignKey' )(to = orm ["%s.%s" % (ApplicationModel ._meta .app_label , ApplicationModel ._meta .object_name )])),
40
- ('expires' , self .gf ('django.db.models.fields.DateTimeField' )()),
41
- ('redirect_uri' , self .gf ('django.db.models.fields.CharField' )(max_length = 255 )),
42
- ('scope' , self .gf ('django.db.models.fields.TextField' )(blank = True )),
43
- ))
44
- db .send_create_signal (u'oauth2_provider' , ['Grant' ])
45
-
46
- # Adding model 'AccessToken'
47
- db .create_table (u'oauth2_provider_accesstoken' , (
48
- (u'id' , self .gf ('django.db.models.fields.AutoField' )(primary_key = True )),
49
- ('user' , self .gf ('django.db.models.fields.related.ForeignKey' )(to = orm ["%s.%s" % (User ._meta .app_label , User ._meta .object_name )])),
50
- ('token' , self .gf ('django.db.models.fields.CharField' )(max_length = 255 )),
51
- ('application' , self .gf ('django.db.models.fields.related.ForeignKey' )(to = orm ["%s.%s" % (ApplicationModel ._meta .app_label , ApplicationModel ._meta .object_name )])),
52
- ('expires' , self .gf ('django.db.models.fields.DateTimeField' )()),
53
- ('scope' , self .gf ('django.db.models.fields.TextField' )(blank = True )),
54
- ))
55
- db .send_create_signal (u'oauth2_provider' , ['AccessToken' ])
56
-
57
- # Adding model 'RefreshToken'
58
- db .create_table (u'oauth2_provider_refreshtoken' , (
59
- (u'id' , self .gf ('django.db.models.fields.AutoField' )(primary_key = True )),
60
- ('user' , self .gf ('django.db.models.fields.related.ForeignKey' )(to = orm ["%s.%s" % (User ._meta .app_label , User ._meta .object_name )])),
61
- ('token' , self .gf ('django.db.models.fields.CharField' )(max_length = 255 )),
62
- ('application' , self .gf ('django.db.models.fields.related.ForeignKey' )(to = orm ["%s.%s" % (ApplicationModel ._meta .app_label , ApplicationModel ._meta .object_name )])),
63
- ('access_token' , self .gf ('django.db.models.fields.related.OneToOneField' )(related_name = 'refresh_token' , unique = True , to = orm ['oauth2_provider.AccessToken' ])),
64
- ))
65
- db .send_create_signal (u'oauth2_provider' , ['RefreshToken' ])
66
-
67
-
68
- def backwards (self , orm ):
69
- # Deleting model 'Application'
70
- db .delete_table (u'oauth2_provider_application' )
71
-
72
- # Deleting model 'Grant'
73
- db .delete_table (u'oauth2_provider_grant' )
74
-
75
- # Deleting model 'AccessToken'
76
- db .delete_table (u'oauth2_provider_accesstoken' )
77
-
78
- # Deleting model 'RefreshToken'
79
- db .delete_table (u'oauth2_provider_refreshtoken' )
80
-
81
-
82
- models = {
83
- u'auth.group' : {
84
- 'Meta' : {'object_name' : 'Group' },
85
- u'id' : ('django.db.models.fields.AutoField' , [], {'primary_key' : 'True' }),
86
- 'name' : ('django.db.models.fields.CharField' , [], {'unique' : 'True' , 'max_length' : '80' }),
87
- 'permissions' : ('django.db.models.fields.related.ManyToManyField' , [], {'to' : u"orm['auth.Permission']" , 'symmetrical' : 'False' , 'blank' : 'True' })
88
- },
89
- u'auth.permission' : {
90
- 'Meta' : {'ordering' : "(u'content_type__app_label', u'content_type__model', u'codename')" , 'unique_together' : "((u'content_type', u'codename'),)" , 'object_name' : 'Permission' },
91
- 'codename' : ('django.db.models.fields.CharField' , [], {'max_length' : '100' }),
92
- 'content_type' : ('django.db.models.fields.related.ForeignKey' , [], {'to' : u"orm['contenttypes.ContentType']" }),
93
- u'id' : ('django.db.models.fields.AutoField' , [], {'primary_key' : 'True' }),
94
- 'name' : ('django.db.models.fields.CharField' , [], {'max_length' : '50' })
95
- },
96
- u"%s.%s" % (User ._meta .app_label , User ._meta .object_name ): {
97
- 'Meta' : {'object_name' : User .__name__ },
98
- 'date_joined' : ('django.db.models.fields.DateTimeField' , [], {'default' : 'datetime.datetime.now' }),
99
- 'email' : ('django.db.models.fields.EmailField' , [], {'max_length' : '75' , 'blank' : 'True' }),
100
- 'first_name' : ('django.db.models.fields.CharField' , [], {'max_length' : '30' , 'blank' : 'True' }),
101
- 'groups' : ('django.db.models.fields.related.ManyToManyField' , [], {'to' : u"orm['auth.Group']" , 'symmetrical' : 'False' , 'blank' : 'True' }),
102
- u'id' : ('django.db.models.fields.AutoField' , [], {'primary_key' : 'True' }),
103
- 'is_active' : ('django.db.models.fields.BooleanField' , [], {'default' : 'True' }),
104
- 'is_staff' : ('django.db.models.fields.BooleanField' , [], {'default' : 'False' }),
105
- 'is_superuser' : ('django.db.models.fields.BooleanField' , [], {'default' : 'False' }),
106
- 'last_login' : ('django.db.models.fields.DateTimeField' , [], {'default' : 'datetime.datetime.now' }),
107
- 'last_name' : ('django.db.models.fields.CharField' , [], {'max_length' : '30' , 'blank' : 'True' }),
108
- 'password' : ('django.db.models.fields.CharField' , [], {'max_length' : '128' }),
109
- 'user_permissions' : ('django.db.models.fields.related.ManyToManyField' , [], {'to' : u"orm['auth.Permission']" , 'symmetrical' : 'False' , 'blank' : 'True' }),
110
- 'username' : ('django.db.models.fields.CharField' , [], {'unique' : 'True' , 'max_length' : '30' })
111
- },
112
- u'contenttypes.contenttype' : {
113
- 'Meta' : {'ordering' : "('name',)" , 'unique_together' : "(('app_label', 'model'),)" , 'object_name' : 'ContentType' , 'db_table' : "'django_content_type'" },
114
- 'app_label' : ('django.db.models.fields.CharField' , [], {'max_length' : '100' }),
115
- u'id' : ('django.db.models.fields.AutoField' , [], {'primary_key' : 'True' }),
116
- 'model' : ('django.db.models.fields.CharField' , [], {'max_length' : '100' }),
117
- 'name' : ('django.db.models.fields.CharField' , [], {'max_length' : '100' })
118
- },
119
- u'oauth2_provider.accesstoken' : {
120
- 'Meta' : {'object_name' : 'AccessToken' },
121
- 'application' : ('django.db.models.fields.related.ForeignKey' , [], {'to' : u"orm['%s.%s']" % (ApplicationModel ._meta .app_label , ApplicationModel ._meta .object_name )}),
122
- 'expires' : ('django.db.models.fields.DateTimeField' , [], {}),
123
- u'id' : ('django.db.models.fields.AutoField' , [], {'primary_key' : 'True' }),
124
- 'scope' : ('django.db.models.fields.TextField' , [], {'blank' : 'True' }),
125
- 'token' : ('django.db.models.fields.CharField' , [], {'max_length' : '255' }),
126
- 'user' : ('django.db.models.fields.related.ForeignKey' , [], {'to' : u"orm['%s.%s']" % (User ._meta .app_label , User ._meta .object_name )})
127
- },
128
- u"%s.%s" % (ApplicationModel ._meta .app_label , ApplicationModel ._meta .object_name ): {
129
- 'Meta' : {'object_name' : ApplicationModel .__name__ },
130
- 'authorization_grant_type' : ('django.db.models.fields.CharField' , [], {'max_length' : '32' }),
131
- 'client_id' : ('django.db.models.fields.CharField' , [], {'default' : "'30f17d266183cd455bc57ce8548a439db3491353'" , 'unique' : 'True' , 'max_length' : '100' }),
132
- 'client_secret' : ('django.db.models.fields.CharField' , [], {'default' : "'18e68df61ad8e1af355644ddf6a636b269b6309aafbd2a34d4f5ed6c5562e44c0792c5b2441571e85cbf8a85249dca5537dedb6fd6f60e134f4a60f3865c8395'" , 'max_length' : '255' , 'blank' : 'True' }),
133
- 'client_type' : ('django.db.models.fields.CharField' , [], {'max_length' : '32' }),
134
- u'id' : ('django.db.models.fields.AutoField' , [], {'primary_key' : 'True' }),
135
- 'name' : ('django.db.models.fields.CharField' , [], {'max_length' : '255' , 'blank' : 'True' }),
136
- 'redirect_uris' : ('django.db.models.fields.TextField' , [], {'blank' : 'True' }),
137
- 'user' : ('django.db.models.fields.related.ForeignKey' , [], {'to' : u"orm['%s.%s']" % (User ._meta .app_label , User ._meta .object_name )})
138
- },
139
- u'oauth2_provider.grant' : {
140
- 'Meta' : {'object_name' : 'Grant' },
141
- 'application' : ('django.db.models.fields.related.ForeignKey' , [], {'to' : u"orm['%s.%s']" % (ApplicationModel ._meta .app_label , ApplicationModel ._meta .object_name )}),
142
- 'code' : ('django.db.models.fields.CharField' , [], {'max_length' : '255' }),
143
- 'expires' : ('django.db.models.fields.DateTimeField' , [], {}),
144
- u'id' : ('django.db.models.fields.AutoField' , [], {'primary_key' : 'True' }),
145
- 'redirect_uri' : ('django.db.models.fields.CharField' , [], {'max_length' : '255' }),
146
- 'scope' : ('django.db.models.fields.TextField' , [], {'blank' : 'True' }),
147
- 'user' : ('django.db.models.fields.related.ForeignKey' , [], {'to' : u"orm['%s.%s']" % (User ._meta .app_label , User ._meta .object_name )})
148
- },
149
- u'oauth2_provider.refreshtoken' : {
150
- 'Meta' : {'object_name' : 'RefreshToken' },
151
- 'access_token' : ('django.db.models.fields.related.OneToOneField' , [], {'related_name' : "'refresh_token'" , 'unique' : 'True' , 'to' : u"orm['oauth2_provider.AccessToken']" }),
152
- 'application' : ('django.db.models.fields.related.ForeignKey' , [], {'to' : u"orm['%s.%s']" % (ApplicationModel ._meta .app_label , ApplicationModel ._meta .object_name )}),
153
- u'id' : ('django.db.models.fields.AutoField' , [], {'primary_key' : 'True' }),
154
- 'token' : ('django.db.models.fields.CharField' , [], {'max_length' : '255' }),
155
- 'user' : ('django.db.models.fields.related.ForeignKey' , [], {'to' : u"orm['%s.%s']" % (User ._meta .app_label , User ._meta .object_name )})
156
- }
157
- }
158
-
159
- complete_apps = ['oauth2_provider' ]
2
+ from __future__ import unicode_literals
3
+
4
+ from django .db import models , migrations
5
+ from django .conf import settings
6
+ import oauth2_provider .generators
7
+ import oauth2_provider .validators
8
+
9
+
10
+ class Migration (migrations .Migration ):
11
+
12
+ dependencies = [
13
+ migrations .swappable_dependency (settings .AUTH_USER_MODEL ),
14
+ ]
15
+
16
+ operations = [
17
+ migrations .CreateModel (
18
+ name = 'AccessToken' ,
19
+ fields = [
20
+ ('id' , models .AutoField (primary_key = True , verbose_name = 'ID' , auto_created = True , serialize = False )),
21
+ ('token' , models .CharField (max_length = 255 , db_index = True )),
22
+ ('expires' , models .DateTimeField ()),
23
+ ('scope' , models .TextField (blank = True )),
24
+ ],
25
+ ),
26
+ migrations .CreateModel (
27
+ name = 'Application' ,
28
+ fields = [
29
+ ('id' , models .AutoField (primary_key = True , verbose_name = 'ID' , auto_created = True , serialize = False )),
30
+ ('client_id' , models .CharField (default = oauth2_provider .generators .generate_client_id , unique = True , max_length = 100 , db_index = True )),
31
+ ('redirect_uris' , models .TextField (validators = [oauth2_provider .validators .validate_uris ], help_text = 'Allowed URIs list, space separated' , blank = True )),
32
+ ('client_type' , models .CharField (max_length = 32 , choices = [('confidential' , 'Confidential' ), ('public' , 'Public' )])),
33
+ ('authorization_grant_type' , models .CharField (max_length = 32 , choices = [('authorization-code' , 'Authorization code' ), ('implicit' , 'Implicit' ), ('password' , 'Resource owner password-based' ), ('client-credentials' , 'Client credentials' )])),
34
+ ('client_secret' , models .CharField (default = oauth2_provider .generators .generate_client_secret , blank = True , max_length = 255 , db_index = True )),
35
+ ('name' , models .CharField (blank = True , max_length = 255 )),
36
+ ('skip_authorization' , models .BooleanField (default = False )),
37
+ ('user' , models .ForeignKey (to = settings .AUTH_USER_MODEL , related_name = 'oauth2_provider_application' )),
38
+ ],
39
+ options = {
40
+ 'abstract' : False ,
41
+ },
42
+ ),
43
+ migrations .CreateModel (
44
+ name = 'Grant' ,
45
+ fields = [
46
+ ('id' , models .AutoField (primary_key = True , verbose_name = 'ID' , auto_created = True , serialize = False )),
47
+ ('code' , models .CharField (max_length = 255 , db_index = True )),
48
+ ('expires' , models .DateTimeField ()),
49
+ ('redirect_uri' , models .CharField (max_length = 255 )),
50
+ ('scope' , models .TextField (blank = True )),
51
+ ('application' , models .ForeignKey (to = settings .OAUTH2_PROVIDER_APPLICATION_MODEL )),
52
+ ('user' , models .ForeignKey (to = settings .AUTH_USER_MODEL )),
53
+ ],
54
+ ),
55
+ migrations .CreateModel (
56
+ name = 'RefreshToken' ,
57
+ fields = [
58
+ ('id' , models .AutoField (primary_key = True , verbose_name = 'ID' , auto_created = True , serialize = False )),
59
+ ('token' , models .CharField (max_length = 255 , db_index = True )),
60
+ ('access_token' , models .OneToOneField (to = 'oauth2_provider.AccessToken' , related_name = 'refresh_token' )),
61
+ ('application' , models .ForeignKey (to = settings .OAUTH2_PROVIDER_APPLICATION_MODEL )),
62
+ ('user' , models .ForeignKey (to = settings .AUTH_USER_MODEL )),
63
+ ],
64
+ ),
65
+ migrations .AddField (
66
+ model_name = 'accesstoken' ,
67
+ name = 'application' ,
68
+ field = models .ForeignKey (to = settings .OAUTH2_PROVIDER_APPLICATION_MODEL ),
69
+ ),
70
+ migrations .AddField (
71
+ model_name = 'accesstoken' ,
72
+ name = 'user' ,
73
+ field = models .ForeignKey (to = settings .AUTH_USER_MODEL , null = True , blank = True ),
74
+ ),
75
+ ]
0 commit comments