Step #1: Register the user.
Register a user at http://localhost:8080/#/register and make sure you can log in via the web interface.
Step #2: Obtain an OAuth2 token.
Information required for obtaining an OAuth2 token:
- OAuth2 client id (see application.yml)
- OAuth2 secret (see application.yml)
- The user name and password used to register the new
user.
- Required scope/s
Then, obtain an OAuth 2 token from the server:
curl -X POST -vu client:secret http://localhost:8080/oauth/token -H "Accept: application/json" -d "username=username&password=password&grant_type=password&scope=read&client_id=clientid&client_secret=secret"
.. returns something like this:
{"access_token":"7916d326-0f7f-430f-8e32-c5135a121052","token_type":"bearer","refresh_token":"2c69ca58-a657-4780-b5d8-dc965d518e9e","expires_in":1037,"scope":"read"}
Step #3: Use the token in calls to protected resources:
Then, the auth token must be supplied in the header on every call:
curl http://localhost:8080/app/rest/books -H "Authorization: Bearer 7916d326-0f7f-430f-8e32-c5135a121052"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…