-
Spring Boot 1.5.10.RELEASE
-
Spring Cloud Edgware.SR3
-
spring boot security
-
spring cloud starter oauth2
Run Auth and Resource Server
cd auth
mvn spring-boot:run
cd resource
mvn spring-boot:run
request access token
curl -s -X POST localhost:8081/oauth/token --user custom-client: -d grant_type=custom -d [email protected]
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiY3VzdG9tLXJlc291cmNlIl0sInVzZXJfbmFtZSI6InRlc3RAdGVzdC5jb20iLCJzY29wZSI6WyJyZWFkIiwid3JpdGUiLCJ0cnVzdCJdLCJleHAiOjE1MTA4NDYxODEsImF1dGhvcml0aWVzIjpbIlVTRVIiXSwianRpIjoiMTIwMzZiMDItMmVjYy00NWRmLTg2ZTAtMjcxOTdlOTJmMTRmIiwiY2xpZW50X2lkIjoiY3VzdG9tLWNsaWVudCJ9.1BI5OeU70z1Ug8W62IuI2bTIbZfBTvE8V7dWr5wGsOQ",
"token_type": "bearer",
"expires_in": 43199,
"scope": "read write trust",
"jti": "12036b02-2ecc-45df-86e0-27197e92f14f"
}
Save access token to TOKEN vaiable. Be careful not to insert a newline(CRLF, LF) character in the middle.
TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiY3VzdG9tLXJlc291cmNlIl0sInVzZXJfbmFtZSI6InRlc3RAdGVzdC5jb20iLCJzY29wZSI6WyJyZWFkIiwid3JpdGUiLCJ0cnVzdCJdLCJleHAiOjE1MTA4NDYxODEsImF1dGhvcml0aWVzIjpbIlVTRVIiXSwianRpIjoiMTIwMzZiMDItMmVjYy00NWRmLTg2ZTAtMjcxOTdlOTJmMTRmIiwiY2xpZW50X2lkIjoiY3VzdG9tLWNsaWVudCJ9.1BI5OeU70z1Ug8W62IuI2bTIbZfBTvE8V7dWr5wGsOQ
get resource from Resource Server
curl -s localhost:8080/ -H "Authorization: Bearer $TOKEN"
Hello, resource!