Skip to content

Commit

Permalink
fix: remove deperecated role names (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsijie authored Feb 10, 2023
1 parent 0640e70 commit ae44b63
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 21 deletions.
1 change: 0 additions & 1 deletion packages/js/src/core/user-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type UserInfoResponse = {
name?: string;
username?: string;
picture?: string;
role_names?: string[];
email?: string;
email_verified?: boolean;
phone_number?: string;
Expand Down
5 changes: 2 additions & 3 deletions packages/js/src/utils/id-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('verifyIdToken', () => {
describe('decodeIdToken', () => {
test('decoding valid JWT should return claims', async () => {
const { privateKey } = await generateKeyPair('RS256');
const jwt = await new SignJWT({ name: '测试用户', avatar: undefined, role_names: ['admin'] })
const jwt = await new SignJWT({ name: '测试用户', avatar: undefined })
.setProtectedHeader({ alg: 'RS256' })
.setIssuer('foo')
.setSubject('bar')
Expand All @@ -229,13 +229,12 @@ describe('decodeIdToken', () => {
exp: 2000,
iat: 1000,
name: '测试用户',
role_names: ['admin'],
});
});

test('decoding valid JWT with wrong payload type should throw', async () => {
const { privateKey } = await generateKeyPair('RS256');
const jwt = await new SignJWT({ name: null, avatar: undefined, role_names: [123] })
const jwt = await new SignJWT({ name: null, avatar: undefined, at_hash: 123 })
.setProtectedHeader({ alg: 'RS256' })
.setIssuer('foo')
.setSubject('bar')
Expand Down
17 changes: 0 additions & 17 deletions packages/js/src/utils/id-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type IdTokenClaims = {
email_verified?: boolean;
phone_number?: Nullable<string>;
phone_number_verified?: boolean;
role_names?: Nullable<string[]>;
};

/* eslint-disable complexity */
Expand Down Expand Up @@ -63,22 +62,6 @@ function assertIdTokenClaims(data: unknown): asserts data is IdTokenClaims {
throw new TypeError(`At path: IdToken.${key}: expected a boolean`);
}
}

if (
data.role_names !== undefined &&
data.role_names !== null &&
!Array.isArray(data.role_names)
) {
throw new TypeError('At path: IdToken.role_names: expected null or an array of strings');
}

if (data.role_names) {
for (const [index, value] of data.role_names.entries()) {
if (typeof value !== 'string') {
throw new TypeError(`At path: IdToken.role_names[${index}]: expected a string`);
}
}
}
}
/* eslint-enable complexity */

Expand Down

0 comments on commit ae44b63

Please sign in to comment.