@@ -132,9 +132,10 @@ def _get_path_of_arbitrary_backend_for_user(user):
132132 return backend_path
133133
134134 @staticmethod
135- def _ensure_access_token_has_password_grant (request ):
135+ def _ensure_access_token_has_password_grant_or_privileged_application (request ):
136136 """
137- Ensures the access token provided has password type grant.
137+ Ensures the access token provided has password type grant, or if 'skip_authorization'
138+ has been enabled, implying this is a trusted application.
138139 """
139140 if is_jwt_authenticated (request ):
140141 jwt_payload = get_decoded_jwt_from_auth (request )
@@ -143,12 +144,17 @@ def _ensure_access_token_has_password_grant(request):
143144 else :
144145 token_query = dot_models .AccessToken .objects .select_related ('user' )
145146 dot_token = token_query .filter (token = request .auth ).first ()
146- if dot_token and dot_token .application .authorization_grant_type == dot_models .Application .GRANT_PASSWORD :
147+ if dot_token and (
148+ dot_token .application .authorization_grant_type == dot_models .Application .GRANT_PASSWORD
149+ or dot_token .application .skip_authorization
150+ ):
147151 return
148152
149153 raise AuthenticationFailed ({
150154 'error_code' : 'non_supported_token' ,
151- 'developer_message' : 'Only access tokens with grant type password are supported.'
155+ 'developer_message' : 'Only Django Oauth Toolkit access tokens for applications which '
156+ 'are trusted (with "skip_authentication" set to True, or with grant type '
157+ 'password) are supported.'
152158 })
153159
154160 @staticmethod
@@ -194,7 +200,7 @@ def post(self, request):
194200 request .user .backend = self ._get_path_of_arbitrary_backend_for_user (request .user )
195201
196202 self ._ensure_user_is_not_disabled (request )
197- self ._ensure_access_token_has_password_grant (request )
203+ self ._ensure_access_token_has_password_grant_or_privileged_application (request )
198204 self ._ensure_jwt_is_asymmetric (request )
199205
200206 login (request , request .user ) # login generates and stores the user's cookies in the session
0 commit comments