Skip to content

Commit 6f72dba

Browse files
David Mullermasci
authored andcommitted
Add skip_authorization_completely to AuthorizationView
1 parent 1fb1b88 commit 6f72dba

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

oauth2_provider/views/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class AuthorizationView(BaseAuthorizationView, FormView):
7575
server_class = Server
7676
validator_class = oauth2_settings.OAUTH2_VALIDATOR_CLASS
7777

78+
skip_authorization_completely = False
79+
7880
def get_initial(self):
7981
# TODO: move this scopes conversion from and to string into a utils function
8082
scopes = self.oauth2_data.get('scope', self.oauth2_data.get('scopes', []))
@@ -123,7 +125,17 @@ def get(self, request, *args, **kwargs):
123125
# Check to see if the user has already granted access and return
124126
# a successful response depending on 'approval_prompt' url parameter
125127
require_approval = request.GET.get('approval_prompt', oauth2_settings.REQUEST_APPROVAL_PROMPT)
126-
if require_approval == 'auto':
128+
129+
# if skip_authorization_completely is True, skip the authorization screen even
130+
# if this is the first use of the application and there was no previous authorization
131+
# useful for in-house applications-> assume an in-house applications are already approved.
132+
if self.skip_authorization_completely:
133+
uri, headers, body, status = self.create_authorization_response(
134+
request=self.request, scopes=" ".join(scopes),
135+
credentials=credentials, allow=True)
136+
return HttpResponseRedirect(uri)
137+
138+
elif require_approval == 'auto':
127139
tokens = request.user.accesstoken_set.filter(application=kwargs['application'],
128140
expires__gt=timezone.now()).all()
129141
# check past authorizations regarded the same scopes as the current one

0 commit comments

Comments
 (0)