Skip to content

Commit bcea6ba

Browse files
committed
refactor oauthmanager scopes management
1 parent f8be2f6 commit bcea6ba

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

flask_rest_jsonapi/api.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,14 @@ def before_request():
100100
endpoint = request.endpoint
101101
resource = self.app.view_functions[endpoint].view_class
102102

103-
scope = self.get_scope(resource, request.method)
103+
scopes = None
104104

105-
valid, req = oauth_manager.verify_request([scope])
105+
if request.args.get('scopes'):
106+
scopes = scopes.split(',')
107+
elif getattr(resource, 'schema'):
108+
scopes = [self.build_scope(resource, request.method)]
109+
110+
valid, req = oauth_manager.verify_request(scopes)
106111

107112
for func in oauth_manager._after_request_funcs:
108113
valid, req = func(valid, req)
@@ -114,15 +119,8 @@ def before_request():
114119

115120
request.oauth = req
116121

117-
def scope_setter(self, func):
118-
"""Plug oauth scope setter function to the API
119-
120-
:param callable func: the callable to use a scope getter
121-
"""
122-
self.get_scope = func
123-
124122
@staticmethod
125-
def get_scope(resource, method):
123+
def build_scope(resource, method):
126124
"""Compute the name of the scope for oauth
127125
128126
:param Resource resource: the resource manager

0 commit comments

Comments
 (0)