Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flask_oauthlib/provider/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ def validate_bearer_token(self, token, scopes, request):
return False

request.user = tok.user
request.client = tok.client
request.scopes = scopes
return True

Expand Down
7 changes: 7 additions & 0 deletions tests/oauth2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def authorized(resp):
return jsonify(resp)
return str(resp)

@app.route('/client')
def client_method():
ret = remote.get("client")
if ret.status not in (200,201):
return abort(ret.status)
return ret.raw_data

@app.route('/address')
def address():
ret = remote.get('address/hangzhou')
Expand Down
5 changes: 5 additions & 0 deletions tests/oauth2/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ def access_token():
def email_api(oauth):
return jsonify(email='me@oauth.net', username=oauth.user.username)

@app.route('/api/client')
@oauth.require_oauth()
def client_api(oauth):
return jsonify(client=oauth.client.name)

@app.route('/api/address/<city>')
@oauth.require_oauth('address')
def address_api(oauth, city):
Expand Down
6 changes: 6 additions & 0 deletions tests/oauth2/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ def test_full_flow(self):
rv = self.client.get('/method/delete')
assert b'DELETE' in rv.data

def test_get_client(self):
rv = self.client.post(authorize_url, data={'confirm': 'yes'})
rv = self.client.get(clean_url(rv.location))
rv = self.client.get("/client")
assert b'dev' in rv.data

def test_invalid_client_id(self):
authorize_url = (
'/oauth/authorize?response_type=code&client_id=confidential'
Expand Down