Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 635
fontanellif Avatar asked Feb 02 '15 00:02

fontanellif


People also ask

How do you get auth tokens in curl?

To obtain the secure token, you make a 'get token' API call in which you supply the 'application_id' and 'application_key' generated when you set up API access. You must also supply an existing User value. The token value is then returned.

Does Curl support OAuth?

Use CURL to run the following OAuth ROPC command in a shell terminal to obtain an access token.

How do I access my API token?

Obtaining the API token To get the API token for a user, an HTTP POST request should be sent to the Token resource. In the post body, username and password are specified in JSON format, and the response body contains a token key with an actual API Token as the value.


1 Answers

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"
like image 119
Rori Stumpf Avatar answered Oct 20 '22 16:10

Rori Stumpf