Skip to content

Commit

Permalink
fixed missing payload encoding conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Juelg committed Apr 23, 2024
1 parent f4d77f4 commit 10eb3da
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/front-token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FrontToken {

static Map<String, dynamic> _parseFrontToken(fronTokenDecoded) {
var base64Decoded = base64Decode(fronTokenDecoded);
String decodedString = new String.fromCharCodes(base64Decoded);
String decodedString = utf8.decode(base64Decoded);
var result = jsonDecode(decodedString);
return result;
}
Expand Down
17 changes: 17 additions & 0 deletions test/accesstoken_http_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ void main() {
}
});

test("should convert utf-8 access token payload to utf-16", () async {
await SuperTokensTestUtils.startST(validity: 3);
SuperTokens.init(apiDomain: apiBasePath);
Request req = SuperTokensTestUtils.getLoginRequestUtf8Encoded();
StreamedResponse streamedResp;
streamedResp = await http.send(req);
var resp = await Response.fromStream(streamedResp);
if (resp.statusCode != 200) {
fail("login failed");
}

var payload = await SuperTokens.getAccessTokenPayloadSecurely();
assert(payload.length == 1);
assert(payload["name"] == "öäü-áàâ");
assert(payload["name"] == "\u00f6\u00e4\u00fc\u002d\u00e1\u00e0\u00e2");
});

test("should be able to refresh a session started w/ CDI 2.18", () async {
await SuperTokensTestUtils.startST(validity: 3);
SuperTokens.init(apiDomain: apiBasePath);
Expand Down
12 changes: 12 additions & 0 deletions test/test-utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ class SuperTokensTestUtils {
return request;
}

static http.Request getLoginRequestUtf8Encoded() {
var loginAPIURL = "$baseUrl/login";
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 öäü-áàâ
}};
var jsonBody = jsonEncode(body);
request.body = jsonBody;
return request;
}

static http.Request getLogin218Request() {
var loginAPIURL = "$baseUrl/login-2.18";
var request = http.Request('POST', Uri.parse(loginAPIURL));
Expand Down

0 comments on commit 10eb3da

Please sign in to comment.