Skip to content

Commit d612e54

Browse files
committed
Added support for singular scope query parameter.
1 parent 427667b commit d612e54

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

oauth2_provider/forms.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
class AllowForm(forms.Form):
77
allow = forms.BooleanField(required=False)
88
redirect_uri = forms.CharField(widget=forms.HiddenInput())
9-
scopes = forms.CharField(required=False, widget=forms.HiddenInput())
9+
scope = forms.CharField(required=False, widget=forms.HiddenInput())
1010
client_id = forms.CharField(widget=forms.HiddenInput())
1111
state = forms.CharField(required=False, widget=forms.HiddenInput())
1212
response_type = forms.CharField(widget=forms.HiddenInput())
1313

14+
def __init__(self, *args, **kwargs):
15+
data = kwargs.get('data')
16+
# backwards compatible support for plural `scopes` query parameter
17+
if data and 'scopes' in data:
18+
data['scope'] = data['scopes']
19+
return super(AllowForm, self).__init__(*args, **kwargs)
20+
1421

1522
class RegistrationForm(forms.ModelForm):
1623
"""

oauth2_provider/views/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ class AuthorizationView(BaseAuthorizationView, FormView):
7171

7272
def get_initial(self):
7373
# TODO: move this scopes conversion from and to string into a utils function
74-
scopes = self.oauth2_data.get('scopes', [])
74+
scopes = self.oauth2_data.get('scope', self.oauth2_data.get('scopes', []))
7575
initial_data = {
7676
'redirect_uri': self.oauth2_data.get('redirect_uri', None),
77-
'scopes': ' '.join(scopes),
77+
'scope': ' '.join(scopes),
7878
'client_id': self.oauth2_data.get('client_id', None),
7979
'state': self.oauth2_data.get('state', None),
8080
'response_type': self.oauth2_data.get('response_type', None),
@@ -90,7 +90,7 @@ def form_valid(self, form):
9090
'state': form.cleaned_data.get('state', None),
9191
}
9292

93-
scopes = form.cleaned_data.get('scopes')
93+
scopes = form.cleaned_data.get('scope')
9494
allow = form.cleaned_data.get('allow')
9595
uri, headers, body, status = self.create_authorization_response(
9696
request=self.request, scopes=scopes, credentials=credentials, allow=allow)

0 commit comments

Comments
 (0)