kuzzleio / sdk-javascript

Kuzzle Javascript SDK. High level library including multi-protocol support, offline resiliency, realtime data and more
http://docs.kuzzle.io/sdk/js/7
Apache License 2.0
39 stars 15 forks source link

kuzzle.auth.login get Invalid JSON payload for JWT error #407

Closed cklinx closed 5 years ago

cklinx commented 5 years ago

Hi, dont know but when i try to connect to my kuzzle server

const jwt = await kuzzle.auth.login('local', credentials); // login

i get this error: Invalid JSON payload for JWT

Username and password are correct cuz if i put wrong values the i get login error.

I try to reinstall a fresh one system but got same error.

Any idea?

Aschen commented 5 years ago

Hi @cklinx , Please can you give me your kuzzle and kuzzle-sdk version ?

cklinx commented 5 years ago

Hi, how can i find out it? I'm using kuzzle in a a docker-compose with this line:

kuzzle: image: kuzzleio/kuzzle:latest

can you write here the commands?

thanks in advance

Aschen commented 5 years ago

@cklinx, You can find out the kuzzle version by typing the following command: curl localhost:7512?pretty | grep version. The version should be the first line (something like "version": "1.x.x")

For the SDK you can find the version in the package.json file, under the kuzzle-sdk dependency

cklinx commented 5 years ago

Thanks for the commands =)

Aschen commented 5 years ago

I was unable to reproduce your issue with the version you provided :(

Can you give the result of the following call ?

    const response = await kuzzle.query({
      controller: 'auth',
      action: 'login',
      strategy: 'local',
      body: {
        username: 'admin',
        password: 'admin'
      }
    })
    console.log(response)
cklinx commented 5 years ago

Sure,

Object {
    "action": "login",
    "collection": null,
    "controller": "auth",
    "error": null,
    "index": null,
    "requestId": "0be152d9-ee5a-4887-9427-48a5f4d7ff22",
    "result": Object {
        "_id": "utente",
        "expiresAt": 1561730629081,
        "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJ1dGVudGUiLCJpYXQiOjE1NjE3MjcwMjksImV4cCI6MTU2MTczMDYyOX0.DPucG0QFHUAyVHw8avdHnZmr_hIMoNXAYQJb2-xjUlE",
        "ttl": 3600000,
    },
    "room": "0be152d9-ee5a-4887-9427-48a5f4d7ff22",
    "status": 200,
    "volatile": Object {
        "sdkInstanceId": "7f3f148b-53f6-4f1d-b33a-3b5fa2d3d1e6",
        "sdkVersion": "6.1.3",
    },
}
Aschen commented 5 years ago

I moved this issue to the Javascript SDK repository since it seems to be related to this project.

Concerning your issue, it seems that the SDK is unable to parse the authentication token returned by Kuzzle (https://github.com/kuzzleio/sdk-javascript/blob/master/src/core/Jwt.js#L48).
But I try to manually set the authentication token manually and the SDK was able to parse it:

kuzzle.jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJ1dGVudGUiLCJpYXQiOjE1NjE3MjcwMjksImV4cCI6MTU2MTczMDYyOX0.DPucG0QFHUAyVHw8avdHnZmr_hIMoNXAYQJb2-xjUlE";

Did you use any transpiler like Typescript or Babel ?

cklinx commented 5 years ago

I'm using Expo with react native. It use Babel.

cklinx commented 5 years ago

Ok using this version "kuzzle-sdk": "6.1.0", its work fine! the problem i think is the "kuzzle-sdk": "^6.1.0", version => 6.1.3.

barroudjo commented 5 years ago

Hello, I faced the same issue, but only when using the transpiled version of kuzzle (ie the one in the dist folder). And it's also with version 6.1.3.

Aschen commented 5 years ago

Hi @cklinx and @barroudjo,

I fixed the issue, a new version of the SDK will be released soon, thanks you for your feedback !

See https://github.com/kuzzleio/sdk-javascript/pull/422

barroudjo commented 5 years ago

Thanks @Aschen !

Aschen commented 5 years ago

Fixed by #422 @barroudjo and @cklinx we will release a new version of the SDK this week