简体   繁体   中英

How to get and use authentication token for JHipster Microservice JWT

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?

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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM