@@ -39,38 +39,44 @@ class AbstractApplication(models.Model):
3939 the registration process as described in :rfc:`2.2`
4040 * :attr:`name` Friendly name for the Application
4141 """
42- CLIENT_CONFIDENTIAL = ' confidential'
43- CLIENT_PUBLIC = ' public'
42+ CLIENT_CONFIDENTIAL = " confidential"
43+ CLIENT_PUBLIC = " public"
4444 CLIENT_TYPES = (
45- (CLIENT_CONFIDENTIAL , _ (' Confidential' )),
46- (CLIENT_PUBLIC , _ (' Public' )),
45+ (CLIENT_CONFIDENTIAL , _ (" Confidential" )),
46+ (CLIENT_PUBLIC , _ (" Public" )),
4747 )
4848
49- GRANT_AUTHORIZATION_CODE = ' authorization-code'
50- GRANT_IMPLICIT = ' implicit'
51- GRANT_PASSWORD = ' password'
52- GRANT_CLIENT_CREDENTIALS = ' client-credentials'
49+ GRANT_AUTHORIZATION_CODE = " authorization-code"
50+ GRANT_IMPLICIT = " implicit"
51+ GRANT_PASSWORD = " password"
52+ GRANT_CLIENT_CREDENTIALS = " client-credentials"
5353 GRANT_TYPES = (
54- (GRANT_AUTHORIZATION_CODE , _ (' Authorization code' )),
55- (GRANT_IMPLICIT , _ (' Implicit' )),
56- (GRANT_PASSWORD , _ (' Resource owner password-based' )),
57- (GRANT_CLIENT_CREDENTIALS , _ (' Client credentials' )),
54+ (GRANT_AUTHORIZATION_CODE , _ (" Authorization code" )),
55+ (GRANT_IMPLICIT , _ (" Implicit" )),
56+ (GRANT_PASSWORD , _ (" Resource owner password-based" )),
57+ (GRANT_CLIENT_CREDENTIALS , _ (" Client credentials" )),
5858 )
5959
60- client_id = models .CharField (max_length = 100 , unique = True ,
61- default = generate_client_id , db_index = True )
62- user = models .ForeignKey (settings .AUTH_USER_MODEL ,
63- related_name = "%(app_label)s_%(class)s" ,
64- null = True , blank = True , on_delete = models .CASCADE )
60+ client_id = models .CharField (
61+ max_length = 100 , unique = True , default = generate_client_id , db_index = True
62+ )
63+ user = models .ForeignKey (
64+ settings .AUTH_USER_MODEL ,
65+ related_name = "%(app_label)s_%(class)s" ,
66+ null = True , blank = True , on_delete = models .CASCADE
67+ )
6568
6669 help_text = _ ("Allowed URIs list, space separated" )
67- redirect_uris = models .TextField (help_text = help_text ,
68- validators = [validate_uris ], blank = True )
70+ redirect_uris = models .TextField (
71+ blank = True , help_text = help_text , validators = [validate_uris ]
72+ )
6973 client_type = models .CharField (max_length = 32 , choices = CLIENT_TYPES )
70- authorization_grant_type = models .CharField (max_length = 32 ,
71- choices = GRANT_TYPES )
72- client_secret = models .CharField (max_length = 255 , blank = True ,
73- default = generate_client_secret , db_index = True )
74+ authorization_grant_type = models .CharField (
75+ max_length = 32 , choices = GRANT_TYPES
76+ )
77+ client_secret = models .CharField (
78+ max_length = 255 , blank = True , default = generate_client_secret , db_index = True
79+ )
7480 name = models .CharField (max_length = 255 , blank = True )
7581 skip_authorization = models .BooleanField (default = False )
7682
@@ -86,9 +92,11 @@ def default_redirect_uri(self):
8692 if self .redirect_uris :
8793 return self .redirect_uris .split ().pop (0 )
8894
89- assert False , "If you are using implicit, authorization_code" \
90- "or all-in-one grant_type, you must define " \
91- "redirect_uris field in your Application model"
95+ assert False , (
96+ "If you are using implicit, authorization_code"
97+ "or all-in-one grant_type, you must define "
98+ "redirect_uris field in your Application model"
99+ )
92100
93101 def redirect_uri_allowed (self , uri ):
94102 """
@@ -118,11 +126,11 @@ def clean(self):
118126 and self .authorization_grant_type \
119127 in (AbstractApplication .GRANT_AUTHORIZATION_CODE ,
120128 AbstractApplication .GRANT_IMPLICIT ):
121- error = _ (' Redirect_uris could not be empty with {0 } grant_type' )
122- raise ValidationError (error .format (self .authorization_grant_type ))
129+ error = _ (" Redirect_uris could not be empty with {grant_type } grant_type" )
130+ raise ValidationError (error .format (grant_type = self .authorization_grant_type ))
123131
124132 def get_absolute_url (self ):
125- return reverse (' oauth2_provider:detail' , args = [str (self .id )])
133+ return reverse (" oauth2_provider:detail" , args = [str (self .id )])
126134
127135 def __str__ (self ):
128136 return self .name or self .client_id
@@ -141,7 +149,7 @@ def is_usable(self, request):
141149
142150class Application (AbstractApplication ):
143151 class Meta (AbstractApplication .Meta ):
144- swappable = ' OAUTH2_PROVIDER_APPLICATION_MODEL'
152+ swappable = " OAUTH2_PROVIDER_APPLICATION_MODEL"
145153
146154
147155@python_2_unicode_compatible
@@ -289,14 +297,17 @@ class AbstractRefreshToken(models.Model):
289297 * :attr:`access_token` AccessToken instance this refresh token is
290298 bounded to
291299 """
292- user = models .ForeignKey (settings .AUTH_USER_MODEL , on_delete = models .CASCADE ,
293- related_name = "%(app_label)s_%(class)s" )
300+ user = models .ForeignKey (
301+ settings .AUTH_USER_MODEL , on_delete = models .CASCADE ,
302+ related_name = "%(app_label)s_%(class)s"
303+ )
294304 token = models .CharField (max_length = 255 , unique = True )
295- application = models .ForeignKey (oauth2_settings .APPLICATION_MODEL ,
296- on_delete = models .CASCADE )
297- access_token = models .OneToOneField (oauth2_settings .ACCESS_TOKEN_MODEL ,
298- related_name = 'refresh_token' ,
299- on_delete = models .CASCADE )
305+ application = models .ForeignKey (
306+ oauth2_settings .APPLICATION_MODEL , on_delete = models .CASCADE )
307+ access_token = models .OneToOneField (
308+ oauth2_settings .ACCESS_TOKEN_MODEL , on_delete = models .CASCADE ,
309+ related_name = "refresh_token"
310+ )
300311
301312 def revoke (self ):
302313 """
0 commit comments