jhipster oauth:如何通过 CURL 获取 access_token [英] jhipster oauth : How can i get the access_token via CURL
问题描述
我正在尝试使用 jhipster 工具来创建一个具有 oauth2 身份验证的新项目.项目示例运行良好,我可以使用 angularjs 界面登录,但无法理解如何创建新用户,然后通过 Curl 命令行为该新用户获取访问令牌.
i'm trying to use the jhipster tool in order to create a new project with the oauth2 authentication. The project example work fine, i can login with the angularjs interface, but can't understand how can i create a new user and then get the access token via Curl command line for this new user.
感谢您的帮助
推荐答案
第 1 步:注册用户.
Step #1: Register the user.
在 http://localhost:8080/#/register 注册用户并确保您可以通过网络登录界面.
Register a user at http://localhost:8080/#/register and make sure you can log in via the web interface.
第 2 步:获取 OAuth2 令牌.
Step #2: Obtain an OAuth2 token.
获取 OAuth2 令牌所需的信息:
Information required for obtaining an OAuth2 token:
- OAuth2 客户端 ID(参见 application.yml)
- OAuth2 机密(请参阅 application.yml)
- 用于注册新用户的用户名和密码用户.
- 所需范围
然后,从服务器获取 OAuth 2 令牌:
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"
.. 返回如下内容:
{"access_token":"7916d326-0f7f-430f-8e32-c5135a121052","token_type":"bearer","refresh_token":"2c69ca58-a657-4780-b5d8-dc965d518e9e","expires_in":1037,"scope":"read"}
第 3 步:在调用受保护资源时使用令牌:
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"
这篇关于jhipster oauth:如何通过 CURL 获取 access_token的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!