oauth2-server/examples/README.md

54 lines
1.7 KiB
Markdown
Raw Normal View History

2015-04-05 21:32:43 +05:30
# Example implementations
2016-01-13 05:58:52 +05:30
## Installation
2016-04-17 17:13:13 +05:30
0. Run `composer install` in this directory to install dependencies
0. Create a private key `openssl genrsa -out private.key 2048`
2016-01-13 05:58:52 +05:30
0. Create a public key `openssl rsa -in private.key -pubout > public.key`
0. `cd` into the public directory
0. Start a PHP server `php -S localhost:4444`
## Testing the client credentials grant example
Send the following cURL request:
```
curl -X "POST" "http://localhost:4444/client_credentials.php/access_token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: 1.0" \
2016-02-12 23:36:31 +05:30
--data-urlencode "grant_type=client_credentials" \
2016-01-13 05:58:52 +05:30
--data-urlencode "client_id=myawesomeapp" \
--data-urlencode "client_secret=abc123" \
2016-02-12 23:36:31 +05:30
--data-urlencode "scope=basic email"
2016-01-13 05:58:52 +05:30
```
## Testing the password grant example
Send the following cURL request:
```
curl -X "POST" "http://localhost:4444/password.php/access_token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: 1.0" \
2016-02-12 23:36:31 +05:30
--data-urlencode "grant_type=password" \
2016-01-13 05:58:52 +05:30
--data-urlencode "client_id=myawesomeapp" \
2016-02-12 23:36:31 +05:30
--data-urlencode "client_secret=abc123" \
2016-01-13 05:58:52 +05:30
--data-urlencode "username=alex" \
--data-urlencode "password=whisky" \
2016-02-12 23:36:31 +05:30
--data-urlencode "scope=basic email"
2016-01-13 05:58:52 +05:30
```
## Testing the refresh token grant example
Send the following cURL request. Replace `{{REFRESH_TOKEN}}` with a refresh token from another grant above:
```
curl -X "POST" "http://localhost:4444/refresh_token.php/access_token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: 1.0" \
--data-urlencode "grant_type=refresh_token" \
--data-urlencode "client_id=myawesomeapp" \
--data-urlencode "client_secret=abc123" \
--data-urlencode "refresh_token={{REFRESH_TOKEN}}"
```