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

Fixed missing payload encoding conversion (from UTF-8 to UTF-16) #56

Merged
merged 3 commits into from
May 8, 2024

Conversation

djuelg
Copy link

@djuelg djuelg commented Apr 23, 2024

Summary of change

Dart Strings always have a UTF-16 encoding. We receive token payloads encoded in UTF-8 from the Supertokens backend. Due to a known issue with jsonDecode in Flutter, the JSON contents are not converted from UTF-8 to UTF-16 encoding. This presents challenges, particularly with strings containing special characters such as ö, ä, or ü.

In the proposed update, before performing JSON decoding, we implement UTF-8 decoding using utf8.decode. This ensures that the resulting data structure is a properly encoded Map<String, dynamic>, where special characters are represented correctly.

Related issues

Test Plan

  • see new test
  • Or manually: Display claims from a token that contains special characters

@rishabhpoddar rishabhpoddar changed the base branch from master to 0.4 April 23, 2024 13:58
@rishabhpoddar
Copy link
Contributor

Hey @djuelg

Thanks for the PR. A few points:

  • Did you run the new unit test you added and that passed? I ask cause setting up the supertokens-core for testing purposes isn't the easiest thing to do, so curious if you needed help with that.
  • Can you bump the patch version of the repo in the various places mentioned in the pull request template?

var request = http.Request('POST', Uri.parse(loginAPIURL));
request.headers['Content-Type'] = "application/json; charset=utf-8";
var body = {"userId": "supertokens-flutter-tests", "payload": {
"name": "\xc3\xb6\xc3\xa4\xc3\xbc\x2d\xc3\xa1\xc3\xa0\xc3\xa2" // UTF-8 encoded öäü-áàâ
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think the login enpoint here actually uses the payload prop in the reuqest to add to the access token payload of the session. So that probably needs to be modified as well

Copy link
Author

@djuelg djuelg Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, that's a mixup with /login-2.18, where the request payload gets passed to the token. Would it be fine to run the test against /login-2.18? Or should I rather adapt the /login node-function?

In the second case, I guess I would need to pass the payload like so: Session.createNewSession(req, res, userId, accessTokenPayload: payloadFromRequest);?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. You should adapt the login API and pass in the payloadFromRequest to the createNewSession function in case the request body has this prop

@djuelg
Copy link
Author

djuelg commented Apr 24, 2024

  • Did you run the new unit test you added and that passed? I ask cause setting up the supertokens-core for testing purposes isn't the easiest thing to do, so curious if you needed help with that.

Yeah no, you got me there. I kind of had hopes that some pipeline might run the tests automatically, so that I can avoid setting up the whole testing-environment for such a small change. I can look into setting it up in a couple of days.

  • Can you bump the patch version of the repo in the various places mentioned in the pull request template?

Will do with next commit, that will also adress the code comments. Have a nice day :)

@rishabhpoddar
Copy link
Contributor

@djuelg did you get around to running the test?

@rishabhpoddar rishabhpoddar changed the base branch from 0.4 to 0.5 May 8, 2024 12:03
@rishabhpoddar rishabhpoddar merged commit 413831d into supertokens:0.5 May 8, 2024
1 of 3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants