jhipster oauth:如何通过 CURL 获取 access_token

jhipster oauth : How can i get the access_token via CURL

我正在尝试使用 jhipster 工具来创建一个具有 oauth2 身份验证的新项目。项目示例工作正常,我可以使用 angularjs 界面登录,但无法理解如何创建新用户,然后通过 Curl 命令行为这个新用户获取访问令牌。

感谢您的帮助

第 1 步:注册用户。

http://localhost:8080/#/register 注册用户并确保您可以通过 Web 界面登录。

第 2 步:获取 OAuth2 令牌。

获取 OAuth2 令牌所需的信息:

  1. OAuth2 客户端 ID(参见 application.yml)
  2. OAuth2 机密(参见 application.yml)
  3. 新注册时使用的用户名和密码 用户。
  4. 必填scope/s

然后,从服务器获取 OAuth 2 令牌:

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 像这样:

{"access_token":"7916d326-0f7f-430f-8e32-c5135a121052","token_type":"bearer","refresh_token":"2c69ca58-a657-4780-b5d8-dc965d518e9e","expires_in":1037,"scope":"read"}

步骤 #3:在调用受保护资源时使用令牌:

然后,必须在每次调用时在 header 中提供身份验证令牌:

curl http://localhost:8080/app/rest/books -H "Authorization: Bearer 7916d326-0f7f-430f-8e32-c5135a121052"