diff --git a/flask_oauthlib/provider/oauth2.py b/flask_oauthlib/provider/oauth2.py index 0af61c87..1f7efaf5 100644 --- a/flask_oauthlib/provider/oauth2.py +++ b/flask_oauthlib/provider/oauth2.py @@ -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 diff --git a/tests/oauth2/client.py b/tests/oauth2/client.py index 1a985844..ae62b2c0 100644 --- a/tests/oauth2/client.py +++ b/tests/oauth2/client.py @@ -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') diff --git a/tests/oauth2/server.py b/tests/oauth2/server.py index 956d2d85..ee70fb90 100644 --- a/tests/oauth2/server.py +++ b/tests/oauth2/server.py @@ -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/') @oauth.require_oauth('address') def address_api(oauth, city): diff --git a/tests/oauth2/test_oauth2.py b/tests/oauth2/test_oauth2.py index 07cb2a9b..e4449a89 100644 --- a/tests/oauth2/test_oauth2.py +++ b/tests/oauth2/test_oauth2.py @@ -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'