Reputation: 524
I created a JHipster microservice App with JWT authentication (I only have the "backend", no Angular GUI).
In my application-dev.yml, I have the following lines:
jhipster:
security:
authentication:
jwt:
secret: password
# Token is valid 24 hours
token-validity-in-seconds: 86400
token-validity-in-seconds-for-remember-me: 2592000
How can I access the API with a client like "Restlet" (Google Chrome extension).
I read something about getting the token when accessing /api/authenticate but it didn't work (JHipster authentication using Postman and JWT)
Where can I retrieve the JWT Token and how to use it in subsequent requests?
Upvotes: 4
Views: 6969
Reputation: 747
You need a token from the JHipster registry. Use a Post to: http://[JhipsterRegistryIP]:[JHPORT]/api/authenticate
with in header:
Content-Type: application/json
and in body:
{"password": "YOURADMINPASSWORD","rememberMe": true,"username": "admin"}
You get a response with token like this:
{ "id_token" : "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTY1MTMxMjE3M30.ywNnrHv-QTjeCDEAjxYhfpOabzmYpSsJufQYlL-dV7NB683rFiCtFvwTYTZuqlu6XBMEKI13_SLFZM3eF8kxgQ" }
Now you can make a request to your microservice with in header:
Authorization: "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTY1MTMxMjE3M30.ywNnrHv-QTjeCDEAjxYhfpOabzmYpSsJufQYlL-dV7NB683rFiCtFvwTYTZuqlu6XBMEKI13_SLFZM3eF8kxgQ"
Upvotes: 4
Reputation: 16284
You've chosen a microservices architecture: so now you need a registry and a gateway( read the doc).
You get a token by authenticating against the gateway then you use this token by passing it on each request with Authorization http header.
Upvotes: 8