Skip to content

Commit f1aade0

Browse files
authored
Merge pull request authlib#75 from azmeuk/readme
Authorization code example
2 parents c9038c1 + e2156a7 commit f1aade0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Before testing, we need to create a client:
4545

4646
![create a client](https://user-images.githubusercontent.com/290496/38811988-081814d4-41c6-11e8-88e1-cb6c25a6f82e.png)
4747

48+
### Password flow example
49+
4850
Get your `client_id` and `client_secret` for testing. In this example, we
4951
have enabled `password` grant types, let's try:
5052

@@ -58,6 +60,27 @@ Because this is an example, every user's password is `valid`. Now you can access
5860
$ curl -H "Authorization: Bearer ${access_token}" http://127.0.0.1:5000/api/me
5961
```
6062

63+
### Authorization code flow example
64+
65+
To test the authorization code flow, you can just open this URL in your browser.
66+
```bash
67+
$ open http://127.0.0.1:5000/oauth/authorize?response_type=code&client_id=${client_id}&scope=profile
68+
```
69+
70+
After granting the authorization, you should be redirected to `${redirect_uri}/?code=${code}`
71+
72+
Then your app can send the code to the authorization server to get an access token:
73+
74+
```bash
75+
$ curl -u ${client_id}:${client_secret} -XPOST http://127.0.0.1:5000/oauth/token -F grant_type=authorization_code -F scope=profile -F code=${code}
76+
```
77+
78+
Now you can access `/api/me`:
79+
80+
```bash
81+
$ curl -H "Authorization: Bearer ${access_token}" http://127.0.0.1:5000/api/me
82+
```
83+
6184
For now, you can read the source in example or follow the long boring tutorial below.
6285

6386
**IMPORTANT**: To test implicit grant, you need to `token_endpoint_auth_method` to `none`.

0 commit comments

Comments
 (0)