Skip to content

Commit 99ff07f

Browse files
committed
userinfo endpoint
1 parent cec6214 commit 99ff07f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ Copy the code value, use `curl` to get the access token:
5050
```
5151
curl -u "${CLIENT_ID}:${CLIENT_SECRET}" -XPOST http://127.0.0.1:5000/oauth/token -F grant_type=authorization_code -F code=RSv6j745Ri0DhBSvi2RQu5JKpIVvLm8SFd5ObjOZZSijohe0
5252
```
53+
54+
Now you can access the userinfo endpoint:
55+
56+
```bash
57+
$ curl -H "Authorization: Bearer ${access_token}" http://127.0.0.1:5000/oauth/userinfo
58+
```

website/routes.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from authlib.integrations.flask_oauth2 import current_token
66
from authlib.oauth2 import OAuth2Error
77
from .models import db, User, OAuth2Client
8-
from .oauth2 import authorization, require_oauth
8+
from .oauth2 import authorization, require_oauth, generate_user_info
99

1010

1111
bp = Blueprint(__name__, 'home')
@@ -97,8 +97,7 @@ def issue_token():
9797
return authorization.create_token_response()
9898

9999

100-
@bp.route('/api/me')
100+
@bp.route('/oauth/userinfo')
101101
@require_oauth('profile')
102102
def api_me():
103-
user = current_token.user
104-
return jsonify(id=user.id, username=user.username)
103+
return jsonify(generate_user_info(current_token.user, current_token.scope))

0 commit comments

Comments
 (0)