Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to obtain JWT token from nTokens staging server #37

Closed
Nopik opened this issue Nov 27, 2021 · 15 comments
Closed

Unable to obtain JWT token from nTokens staging server #37

Nopik opened this issue Nov 27, 2021 · 15 comments

Comments

@Nopik
Copy link

Nopik commented Nov 27, 2021

Hello,
With the 1.2.6 SDK, I'm trying following code to obtain JWT from nTokens staging server:

    const anchorDomain = 'staging.ntokens.com';
    final toml = await StellarToml.fromDomain(anchorDomain);

    final webAuth = WebAuth(
      toml.generalInformation?.webAuthEndpoint,
      Network.TESTNET,
      toml.generalInformation?.signingKey,
      anchorDomain,
    );

    final jwt = await webAuth.jwtToken(accountId, [keypair]);

and while equivalent code works on backend (JS SDK), I'm receiving error from

SubmitCompletedChallengeResponse result = await httpClient
:

{\"detail\":\"Unsupported media type \\"text/plain; charset=utf-8\\" in request.\"}

Can you please make sure that the Flutter SDK works with the nTokens server? I'm not sure if the problem is on the Flutter SDK side, or nTokens are too restrictive.

@christian-rogobete
Copy link
Contributor

Hi @Nopik, I committed a potential fix: 9899641
Can you pls. test if it works with that and let me know?

@Nopik
Copy link
Author

Nopik commented Nov 27, 2021

@christian-rogobete so, it changed something. Now the server responds with: {\"detail\":\"JSON parse error - Expecting value: line 1 column 1 (char 0)\"}.

@Nopik
Copy link
Author

Nopik commented Nov 27, 2021

The body being sent seems valid: AAAAAgAAAADCJEP+4WNwqXHn8bDhO8ptn3t3d7ixSw1W76+S3mmYpwAAAMgAAAAAAAAAAAAAAAEAAAAAYaI2MQAAAABhojm1AAAAAAAAAAIAAAABAAAAAGwyFuYpS8T0b8tAEGWTC9dx7QyWwydi7wK1iNC/GUzDAAAACgAAABhzdGFnaW5nLm50b2tlbnMuY29tIGF1dGgAAAABAAAAQG1RTkpzOUt6cFJYeHBwMlRrWlEzdmZ5N0E5emo2YWNFMWc4bGFUL1lHOTJ6L3lJelZQbS8yZHdVbVFtNXE1WC8AAAABAAAAAMIkQ/7hY3CpcefxsOE7ym2fe3d3uLFLDVbvr5LeaZinAAAACgAAAA93ZWJfYXV0aF9kb21haW4AAAAAAQAAABNzdGFnaW5nLm50b2tlbnMuY29tAAAAAAAAAAAC3mmYpwAAAECvHgdgcK7B9acr9pQ8cGaq2YYqoETdr6wkiUW/9ravbu7nQMvr0qoB8pATevSs3CiWPkmFF7SNUM4Ne3lyQTYFvxlMwwAAAEA/iHIOZ+hqt+MFJB3yL/Jrt0fTJ852K635WrEtFgHZ21Kd1HWviA9iufL/i84QYFW79x4jSCVJQl+GNwhg1DwL

@christian-rogobete
Copy link
Contributor

I think it needs to be json like: {transaction="AAA..."},one moment

@christian-rogobete
Copy link
Contributor

@Nopik can you please try it again? b21749b

@Nopik
Copy link
Author

Nopik commented Nov 27, 2021

@christian-rogobete It would really be more efficient if you would try to run this code yourself. Exception: Bad state: Cannot set the body fields of a Request with content-type "application/json".

@Nopik
Copy link
Author

Nopik commented Nov 27, 2021

Adding json.encode() solves that problem (body: json.encode({"transaction": base64EnvelopeXDR})), and now JWT token is obtained properly. Please release the 1.2.7 with those changes

@christian-rogobete
Copy link
Contributor

@Nopik try it one more time please with the latest commit. I think it will solve the problem too. Pls. let me know

@Nopik
Copy link
Author

Nopik commented Nov 27, 2021

@christian-rogobete please see my previous comment. If I leave the json.encode in place, but remove the headers like in your last commit, the original problem (Invalid media type) appears again.

@christian-rogobete
Copy link
Contributor

ok, I need to fix the test too first. This is your code, right
Screenshot 2021-11-27 at 15 08 43
?

@Nopik
Copy link
Author

Nopik commented Nov 27, 2021

@christian-rogobete yes, that is my code now, it works for me.

@christian-rogobete
Copy link
Contributor

christian-rogobete commented Nov 27, 2021

ok, I will fix the test and then release a new version, thx

@Nopik
Copy link
Author

Nopik commented Nov 27, 2021

Great, thanks.

@christian-rogobete
Copy link
Contributor

yw see release 1.2.7

@Nopik
Copy link
Author

Nopik commented Nov 27, 2021

It works, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants