jhipster的OAuth:我怎样才能通过袅袅的access_token [英] jhipster oauth : How can i get the access_token via CURL
问题描述
我试图以创建具有的oauth2验证一个新的项目使用jhipster工具。该项目的例子做工精细,我可以用angularjs界面登录,但不明白我怎么可以创建一个新用户,然后获得通过curl命令行访问令牌为此新用户。
感谢您的帮助。
第1步:注册用户
在注册用户的http://本地主机:8080 /#/注册并确保您可以通过网络登录接口。
第二步:获取的OAuth2令牌
用于获取的OAuth2令牌所需的信息:
- 的OAuth2客户端ID(见application.yml)
- 的OAuth2秘密(见application.yml)
- 的用户名和密码,用于注册新
用户。 - 必需范围/ S
然后,从服务器获取一个OAuth 2令牌:
卷曲-X POST -vu客户端:秘密的http://本地主机:8080 /的OAuth /令牌-H接受:应用/ JSON-d \"username=username&password=password&grant_type=password&scope=read&client_id=clientid&client_secret=secret\"
..返回是这样的:
<$p$p><$c$c>{\"access_token\":\"7916d326-0f7f-430f-8e32-c5135a121052\",\"token_type\":\"bearer\",\"refresh_token\":\"2c69ca58-a657-4780-b5d8-dc965d518e9e\",\"expires_in\":1037,\"scope\":\"read\"}第三步:使用呼叫令牌保护的资源:
然后,身份验证令牌必须在每次调用头提供的:
卷曲的http://本地主机:8080 /应用/ REST /书籍-H授权:承载7916d326-0f7f-430F-8e32-c5135a121052
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.
Thanks for your help
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:
- OAuth2 client id (see application.yml)
- OAuth2 secret (see application.yml)
- The user name and password used to register the new user.
- 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"
这篇关于jhipster的OAuth:我怎样才能通过袅袅的access_token的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!