jhipster oauth : How can i get the access_token via CURL

最后都变了- 提交于 2019-11-27 22:25:08

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:

  1. OAuth2 client id (see application.yml)
  2. OAuth2 secret (see application.yml)
  3. The user name and password used to register the new user.
  4. 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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!