Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

angularjs - jhipster oauth : How can i get the access_token via 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.

Thanks for your help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. OAuth2 client id (see application.yml)
  2. OAuth2 secret (see application.yml)
  3. The user name and password used to register the new user.
  4. 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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...