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 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/bright-balloons-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/auth': major
---

Changed the type of ParsedToken value from any to unknown
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
6 changes: 3 additions & 3 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,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': { key1: 'value1' },
'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 { key1: string }).key1).to.equal('value1');
});
});
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