4

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?

dfsg76
  • 504
  • 1
  • 6
  • 22

2 Answers2

8

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.

Gaël Marziou
  • 16,028
  • 4
  • 38
  • 49
  • 1
    If we want to have the sessionless tocken, we just wanted to save the tocken along with the user table, pass the same tocken on every request till i update the new tocken. Is this possible to achieve with current Jhipster version – Jinna Balu Aug 20 '17 at 22:22
  • 2
    Everything is possible, it's just a code generator. You can do what you want with generated code, it's yours. – Gaël Marziou Aug 21 '17 at 09:03
  • 2
    I was expecting some help from your people. I know that was my code. Answer was just to comment but not related to any help. – Jinna Balu Aug 21 '17 at 10:51
4

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"

FChiri
  • 707
  • 8
  • 14