9

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

fontanellif
  • 165
  • 1
  • 3
  • 7

1 Answers1

10

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"
Rori Stumpf
  • 1,912
  • 19
  • 26
  • Rori, i have another problem. Now i deployed a server and i'm trying to get the access_token via ajax from a different interface (no jhipster interface) Here you can find my code: https://jsfiddle.net/rpdyr97j/2/ Can you help me? – fontanellif Apr 23 '15 at 23:24