小编典典

jhipster oauth:如何通过CURL获取access_token

spring-boot

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

谢谢你的帮助


阅读 498

收藏
2020-05-30

共1个答案

小编典典

步骤1:注册用户。

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

步骤2:获取OAuth2令牌。

获取OAuth2令牌所需的信息:

  1. OAuth2客户端ID(请参阅application.yml)
  2. OAuth2机密(请参阅application.yml)
  3. 用于注册新用户的用户名和密码。
  4. 所需范围

然后,从服务器获取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"

..返回如下内容:

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

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

然后,必须在每次调用的标头中提供auth令牌:

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