【发布时间】:2015-03-31 21:53:12
【问题描述】:
我正在尝试使用 jhipster 工具来创建一个具有 oauth2 身份验证的新项目。项目示例工作正常,我可以使用 angularjs 界面登录,但不明白如何创建一个新用户,然后通过 Curl 命令行为这个新用户获取访问令牌。
感谢您的帮助
【问题讨论】:
标签: angularjs curl spring-boot jhipster spring-security-oauth2
我正在尝试使用 jhipster 工具来创建一个具有 oauth2 身份验证的新项目。项目示例工作正常,我可以使用 angularjs 界面登录,但不明白如何创建一个新用户,然后通过 Curl 命令行为这个新用户获取访问令牌。
感谢您的帮助
【问题讨论】:
标签: angularjs curl spring-boot jhipster spring-security-oauth2
第 1 步:注册用户。
在http://localhost:8080/#/register注册用户并确保您可以通过网络界面登录。
第 2 步:获取 OAuth2 令牌。
获取 OAuth2 令牌所需的信息:
然后,从服务器获取 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 步:在调用受保护资源时使用令牌:
然后,必须在每次调用的标头中提供身份验证令牌:
curl http://localhost:8080/app/rest/books -H "Authorization: Bearer 7916d326-0f7f-430f-8e32-c5135a121052"
【讨论】: