diff --git a/tests/test_oauth2.py b/tests/test_oauth2.py index a4fb829550749047628f52e89800adf4fd51949f..17d9cb701f9a0b7afefe24f1cf6e0057df923594 100644 --- a/tests/test_oauth2.py +++ b/tests/test_oauth2.py @@ -90,6 +90,12 @@ class TestViews(UffdTestCase): r = self.client.get(path=url_for('oauth2.authorize', response_type='code', client_id='test', state='teststate', redirect_uri='http://localhost:5009/callback'), follow_redirects=False) self.assert_authorization(r) + # Regression test for #115 (OAuth2 authorize endpoint rejects empty scope parameter) + def test_authorization_empty_scope(self): + self.login_as('user') + r = self.client.get(path=url_for('oauth2.authorize', response_type='code', client_id='test', state='teststate', scope='', redirect_uri='http://localhost:5009/callback'), follow_redirects=False) + self.assert_authorization(r) + def test_authorization_invalid_scope(self): self.login_as('user') r = self.client.get(path=url_for('oauth2.authorize', response_type='code', client_id='test', state='teststate', redirect_uri='http://localhost:5009/callback', scope='invalid'), follow_redirects=False) diff --git a/uffd/oauth2/views.py b/uffd/oauth2/views.py index 001e37540f0bcebea80cbdc8904e5d58e807dc7c..3b580aef038a4deff37347ba7584c17475caaf71 100644 --- a/uffd/oauth2/views.py +++ b/uffd/oauth2/views.py @@ -50,6 +50,8 @@ class UffdRequestValidator(oauthlib.oauth2.RequestValidator): return oauthreq.client.default_scopes def validate_scopes(self, client_id, scopes, client, oauthreq, *args, **kwargs): + if scopes == ['']: + oauthreq.scopes = scopes = self.get_default_scopes(client_id, oauthreq) return set(scopes).issubset({'profile'}) def save_authorization_code(self, client_id, code, oauthreq, *args, **kwargs):