diff --git a/lib/src/front-token.dart b/lib/src/front-token.dart index 084da16..499e41f 100644 --- a/lib/src/front-token.dart +++ b/lib/src/front-token.dart @@ -31,7 +31,7 @@ class FrontToken { static Map _parseFrontToken(fronTokenDecoded) { var base64Decoded = base64Decode(fronTokenDecoded); - String decodedString = new String.fromCharCodes(base64Decoded); + String decodedString = utf8.decode(base64Decoded); var result = jsonDecode(decodedString); return result; } diff --git a/test/accesstoken_http_test.dart b/test/accesstoken_http_test.dart index b3930c6..d8be239 100644 --- a/test/accesstoken_http_test.dart +++ b/test/accesstoken_http_test.dart @@ -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); diff --git a/test/test-utils.dart b/test/test-utils.dart index 61c227d..41751b5 100644 --- a/test/test-utils.dart +++ b/test/test-utils.dart @@ -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));