How to get and use authentication token for JHipster Microservice JWT

Viewed 6107

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?

2 Answers

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"

Related