Skip to content

Commit 1af178f

Browse files
authored
Add Type Checking to ParseToken Map (#7351)
1 parent 1ff891c commit 1af178f

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

.changeset/bright-balloons-talk.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/auth': major
3+
---
4+
5+
Changed the type of ParsedToken value from any to unknown

common/api-review/auth.api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ export function parseActionCodeURL(link: string): ActionCodeURL | null;
550550

551551
// @public
552552
export interface ParsedToken {
553-
[key: string]: any;
553+
[key: string]: unknown;
554554
'auth_time'?: string;
555555
'exp'?: string;
556556
'firebase'?: {

packages/auth/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@
122122
"@firebase/app": "0.9.13",
123123
"@rollup/plugin-json": "4.1.0",
124124
"@rollup/plugin-strip": "2.1.0",
125+
"@types/express": "4.17.17",
125126
"chromedriver": "98.0.1",
126127
"rollup": "2.79.1",
127128
"rollup-plugin-sourcemaps": "0.6.3",
128129
"rollup-plugin-typescript2": "0.31.2",
129130
"selenium-webdriver": "4.8.0",
130-
"typescript": "4.7.4",
131-
"@types/express": "4.17.17",
132-
"totp-generator": "0.0.14"
131+
"totp-generator": "0.0.14",
132+
"typescript": "4.7.4"
133133
},
134134
"repository": {
135135
"directory": "packages/auth",

packages/auth/src/core/user/id_token_result.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import chaiAsPromised from 'chai-as-promised';
2020
import * as sinon from 'sinon';
2121

2222
import { ProviderId } from '../../model/enums';
23+
import { ParsedToken } from '../../model/public_types';
2324
import { FirebaseError } from '@firebase/util';
2425

2526
import { makeJWT } from '../../../test/helpers/jwt';
@@ -139,4 +140,15 @@ describe('core/user/id_token_result', () => {
139140
'Firebase: An internal AuthError has occurred. (auth/internal-error).'
140141
);
141142
});
143+
144+
it('Parses custom claims with multiple types', () => {
145+
const token: ParsedToken = {
146+
'string_claim': 'foo',
147+
'object_claim': { key1: 'value1' },
148+
'boolean_claim': true
149+
};
150+
expect(token.boolean_claim as boolean).to.equal(true);
151+
expect(token.string_claim as string).to.equal('foo');
152+
expect((token.object_claim as { key1: string }).key1).to.equal('value1');
153+
});
142154
});

packages/auth/src/model/public_types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export interface ParsedToken {
106106
'identities'?: Record<string, string>;
107107
};
108108
/** Map of any additional custom claims. */
109-
[key: string]: any;
109+
[key: string]: unknown;
110110
}
111111

112112
/**

0 commit comments

Comments
 (0)