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

Add Type Checking to ParseToken Map #7351

Merged
merged 10 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion common/api-review/auth.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export function parseActionCodeURL(link: string): ActionCodeURL | null;

// @public
export interface ParsedToken {
[key: string]: any;
[key: string]: unknown;
'auth_time'?: string;
'exp'?: string;
'firebase'?: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,6 @@
"watch": "1.0.2",
"webpack": "4.46.0",
"yargs": "17.7.1"
}
},
"dependencies": {}
renkelvin marked this conversation as resolved.
Show resolved Hide resolved
}
7 changes: 4 additions & 3 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"@firebase/component": "0.6.4",
"@firebase/logger": "0.4.0",
"@firebase/util": "1.9.3",
"karma-cli": "2.0.0",
renkelvin marked this conversation as resolved.
Show resolved Hide resolved
"node-fetch": "2.6.7",
"tslib": "^2.1.0"
},
Expand All @@ -122,14 +123,14 @@
"@firebase/app": "0.9.11",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-strip": "2.1.0",
"@types/express": "4.17.17",
"chromedriver": "98.0.1",
"rollup": "2.79.1",
"rollup-plugin-sourcemaps": "0.6.3",
"rollup-plugin-typescript2": "0.31.2",
"selenium-webdriver": "4.8.0",
"typescript": "4.7.4",
"@types/express": "4.17.17",
"totp-generator": "0.0.14"
"totp-generator": "0.0.14",
"typescript": "4.7.4"
},
"repository": {
"directory": "packages/auth",
Expand Down
12 changes: 12 additions & 0 deletions packages/auth/src/core/user/id_token_result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import chaiAsPromised from 'chai-as-promised';
import * as sinon from 'sinon';

import { ProviderId } from '../../model/enums';
import { ParsedToken } from '../../model/public_types';
import { FirebaseError } from '@firebase/util';

import { makeJWT } from '../../../test/helpers/jwt';
Expand Down Expand Up @@ -139,4 +140,15 @@ describe('core/user/id_token_result', () => {
'Firebase: An internal AuthError has occurred. (auth/internal-error).'
);
});

it('Parses custom claims with multiple types', () => {
const token: ParsedToken = {
'string_claim': 'foo',
'object_claim': 'bar',
renkelvin marked this conversation as resolved.
Show resolved Hide resolved
'boolean_claim': true
};
expect(token.boolean_claim as boolean).to.equal(true);
expect(token.string_claim as string).to.equal('foo');
expect(token.object_claim as object).to.equal('bar');
});
});
2 changes: 1 addition & 1 deletion packages/auth/src/model/public_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export interface ParsedToken {
'identities'?: Record<string, string>;
};
/** Map of any additional custom claims. */
[key: string]: any;
[key: string]: unknown;
}

/**
Expand Down