https://github.com/esemesek/spring-oauth2-example
Spring oauth2 example
https://github.com/esemesek/spring-oauth2-example
gradle java java-8 oauth2 spring spring-boot spring-security springboot springframework
Last synced: about 1 month ago
JSON representation
Spring oauth2 example
- Host: GitHub
- URL: https://github.com/esemesek/spring-oauth2-example
- Owner: Esemesek
- License: mit
- Created: 2017-06-24T08:32:00.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-24T10:15:20.000Z (almost 9 years ago)
- Last Synced: 2025-11-08T06:03:08.382Z (7 months ago)
- Topics: gradle, java, java-8, oauth2, spring, spring-boot, spring-security, springboot, springframework
- Language: Java
- Homepage:
- Size: 58.6 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# What is this?
Sample SpringBoot application with OAuth2 based authorization.
# How to use?
#### Boot run application
```bash
./gradlew clean bootRun
```
#### Get access token with password
```bash
curl -XPOST -vu app:secret "http://localhost:9000/server/oauth/token?username=admin&password=admin&grant_type=password"
```
Response:
```bash
{
"access_token":"aa1dbe69-b03a-4517-966f-a9bd5e0e4747",
"token_type":"bearer",
"refresh_token":"89472ee5-01b1-400b-8fcf-413cf52df7f4",
"expires_in":1799,
"scope":"read write"
}
```
#### Get access token with refresh token
```bash
curl -XPOST -vu app:secret "http://localhost:9000/server/oauth/token?refresh_token=89472ee5-01b1-400b-8fcf-413cf52df7f4&grant_type=refresh_token"
```
Response:
```bash
{
"access_token":"262f25ab-943e-4014-b254-542acc808d22",
"token_type":"bearer",
"refresh_token":"89472ee5-01b1-400b-8fcf-413cf52df7f4",
"expires_in":1799,
"scope":"read write"
}
```
#### Access unsecured resources
```bash
curl -XGET http://localhost:9000/server/unsecured
```
Response:
```bash
Just public stuff
```
#### Access secured resources
```bash
curl -XGET http://localhost:9000/server/secured
```
Response:
```bash
{
"timestamp":1498298747485,
"status":401,
"error":"Unauthorized",
"message":"Access Denied",
"path":"/server/secured"
}
```
Get access_token
```bash
curl -XPOST -vu app:secret "http://localhost:9000/server/oauth/token?username=admin&password=admin&grant_type=password"
```
Response:
```bash
{
"access_token":"2782cbd7-852c-41f1-9477-7e2a78e6fe38",
"token_type":"bearer",
"refresh_token":"89f7bf5a-720b-42e8-8b47-a80222a4fbdd",
"expires_in":1799,
"scope":"read write"
}
```
Request resource with Authorization header
```bash
curl -XGET -H "Authorization: Bearer 2782cbd7-852c-41f1-9477-7e2a78e6fe38" http://localhost:9000/server/secured
```
Response:
```bash
Secret stuff
```