0
votes

I have a simple nativeScript application (ng-groceries ), which I created by following up a tutorial. And Now I have also managed to get Jhipster Microservice and Jhipster Microservice Gateway App is up and running. I am trying to login from nativeScript app to Jhipster app. I have searched many places, tried to understand generated code , but not able to figure out the solution. I know this has to do something with JWT token, Can someone please point me in the correct direction, or give an approach to the solution. It will be great help.

OK.

I have tried following things:

  1. Tried calling http://169.254.86.103:8080/FITHSERVICEMONGO/api/authenticate/" in loginService.ts. but can not see any thing on the console of Jhipster service server.
    169.254.86.103 is the external IP given when I start Jhipster service app by mvnw.

  2. FITHSERVICEMONGO is the name of my service app.I had also tried removing this from url.When I login from gateway app from UI,the request that gets is http://169.254.86.103:8080/api/authenticate.I had tried with this too. same ,nothing on service console nor on gateway app console. both are started by mvnw

  3. To check of this IP is really accessible from my emulator . I tried accessing //169.254.86.103:8080/#/ from emulator browser. It works. The gateway application works in browser. where as //localhost:8080/#/. was not working.

  4. I was expecting that, when I send an authenticate request with params as username and password. I will get a JWT token in return and that token I will pass with every subsequent request.

the syntax of my code is :

http.post(
      //BackendService.apiUrl + "oauth/token",
        "BackendService.apiUrl" + "/FITHSERVICEMONGO/api/authenticate/",
      JSON.stringify({
        username: user.email,
        password: user.password

      }),
      { Content-Type: "application/json"}
    )
1
What have you tried so far? Code samples and thorough explanation of your problem goes a long way in getting a quality answer, and possibly one that will help with your issue. - pkanev
@pkanev, I have edited my questions , please review the questions now, and see if you can point me to correct direction. Thanks. - Steve.frank

1 Answers

0
votes

To authenticate a third party front-end app with JHipster's back-end you can do the same thing as the angular front-end, calling /api/authenticate and using passing the received the jwt token in api headers. Swagger UI is your friend on order to achieve this.

Here is how to retrieve the JWT token using curl:

curl -X POST localhost:8080/api/authenticate -d '{"password":"admin","username":"admin"}' -H 'Content-Type: application/json' 

Sample authenticated request:

curl -X POST localhost:8080/api/users -H 'Authorization: Bearer YOURTOKENHERE'