Skip to content

Decode UTF-8 in ID Token. Fix #4174. #4357

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

Merged
merged 2 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-carrots-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/auth": patch
---

Decode UTF-8 in ID Token. Fix #4174.
4 changes: 2 additions & 2 deletions packages/auth/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -114,7 +114,7 @@ gulp.task('serve', () => {
);
app.use(express.static(__dirname));

app.listen(4000);
app.listen(4001);
});

gulp.task('default', gulp.parallel('cjs', 'esm'));
4 changes: 2 additions & 2 deletions packages/auth/protractor_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@

var allTests = require('./generated/all_tests');

var TEST_SERVER = 'http://localhost:4000';
var TEST_SERVER = 'http://localhost:4001';

var FLAKY_TEST_RETRIAL = 3;

Expand Down
5 changes: 4 additions & 1 deletion packages/auth/src/idtoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

goog.provide('fireauth.IdToken');

goog.require('goog.crypt');
goog.require('goog.crypt.base64');


Expand Down Expand Up @@ -244,7 +245,9 @@ fireauth.IdToken.parseIdTokenClaims = function(tokenString) {
jsonInfo += '.';
}
try {
const token = JSON.parse(goog.crypt.base64.decodeString(jsonInfo, true));
const decodedClaims = goog.crypt.utf8ByteArrayToString(
goog.crypt.base64.decodeStringToByteArray(jsonInfo));
const token = JSON.parse(decodedClaims);
return /** @type {?Object} */ (token);
} catch (e) {}
return null;
Expand Down
56 changes: 56 additions & 0 deletions packages/auth/test/idtoken_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ var tokenCustomClaim = 'HEAD.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5j' +
'bl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn19.SIGNATURE';


// "iss": "https://securetoken.google.com/projectId",
// "name": "John Doe",
// "role": "Админ", // <---- Note non-ascii characters here
// "aud": "projectId",
// "auth_time": 1522715325,
// "sub": "nep2uwNCK4PqjvoKjb0InVJHlGi1",
// "iat": 1522776807,
// "exp": 1522780575,
// "email": "[email protected]",
// "email_verified": true,
// "firebase": {
// "identities": {
// "email": [
// "[email protected]"
// ]
// },
// "sign_in_provider": "custom"
// }
var tokenCustomClaimWithUnicodeChar = 'HEAD.eyJpc3MiOiJodHRwczovL3NlY3VyZXRv' +
'a2VuLmdvb2dsZS5jb20vcHJvamVjdElkIiwibmFtZSI6IkpvaG4gRG9lIiwicm9sZSI6ItC' +
'Q0LTQvNC40L0iLCJhdWQiOiJwcm9qZWN0SWQiLCJhdXRoX3RpbWUiOjE1MjI3MTUzMjUsIn' +
'N1YiI6Im5lcDJ1d05DSzRQcWp2b0tqYjBJblZKSGxHaTEiLCJpYXQiOjE1MjI3NzY4MDcsI' +
'mV4cCI6MTUyMjc4MDU3NSwiZW1haWwiOiJ0ZXN0dXNlckBnbWFpbC5jb20iLCJlbWFpbF92' +
'ZXJpZmllZCI6dHJ1ZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJ0ZXN' +
'0dXNlckBnbWFpbC5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJjdXN0b20ifX0=.SIGNA' +
'TURE';


// "iss": "https://securetoken.google.com/projectId",
// "name": "John Doe",
// "aud": "projectId",
Expand Down Expand Up @@ -405,3 +433,31 @@ function testParseIdTokenClaims_customClaims() {
},
tokenJSON);
}


function testParseIdTokenClaims_tokenCustomClaimWithUnicodeChar() {
const tokenJSON = fireauth.IdToken.parseIdTokenClaims(
tokenCustomClaimWithUnicodeChar);
assertObjectEquals(
{
'iss': 'https://securetoken.google.com/projectId',
'name': 'John Doe',
'role': 'Админ',
'aud': 'projectId',
'auth_time': 1522715325,
'sub': 'nep2uwNCK4PqjvoKjb0InVJHlGi1',
'iat': 1522776807,
'exp': 1522780575,
'email': "[email protected]",
'email_verified': true,
'firebase': {
'identities': {
'email': [
'[email protected]'
]
},
'sign_in_provider': 'custom'
}
},
tokenJSON);
}