Skip to content

Commit

Permalink
Merge branch 'release-2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
jsconan committed Jun 20, 2023
2 parents 2e346a3 + e0577fa commit e43c749
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oat-sa/tao-core-sdk",
"version": "2.0.1",
"version": "2.0.2",
"displayName": "TAO Core SDK",
"description": "Core libraries of TAO",
"homepage": "https://github.com/oat-sa/tao-core-sdk-fe#readme",
Expand Down
6 changes: 5 additions & 1 deletion src/core/jwt/jwtToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
*/
export function parseJwtPayload(token) {
try {
return JSON.parse(atob(token.split('.')[1]));
let base64Payload = token.split('.')[1];
base64Payload = base64Payload.replace(/-/g, '+'); // replace - with +
base64Payload = base64Payload.replace(/_/g, '/'); // replace _ with /

return JSON.parse(atob(base64Payload));
} catch (e) {
return null;
}
Expand Down
8 changes: 8 additions & 0 deletions test/core/jwt/jwtToken/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ define(['core/jwt/jwtToken'], jwtToken => {
assert.equal(parseJwtPayload(), null, 'missing token returns null');
});

QUnit.test('parses payload object from full token with unsupported characters', assert => {
assert.expect(2);
const token = 'eyJhbGciOiJIUzI1NiJ9.eyJmb28iOiI_In0.qXbg9lEnmvDekuDfNqiAdqYb3Yx1iTLw7RyUGoz5I9w';
const result = parseJwtPayload(token);
assert.ok(typeof result === 'object', 'parsed payload is an object');
assert.equal(result.foo, '?');
});

QUnit.module('getJwtTTL');

const time1 = 1620651921250;
Expand Down

0 comments on commit e43c749

Please sign in to comment.