We are using @okta/okta-auth-js
version 7.5.1
for a react 18 app. Our security team is helping us configure the access token with the claims we need. This is what they look like
But the AccessToken
type is defined with claims
as UserClaims
and they look like:
export declare type UserClaims<T extends CustomUserClaims = CustomUserClaims> = T & {
auth_time?: number;
aud?: string;
email?: string;
email_verified?: boolean;
exp?: number;
family_name?: string;
given_name?: string;
iat?: number;
iss?: string;
jti?: string;
locale?: string;
name?: string;
nonce?: string;
preferred_username?: string;
sub: string;
updated_at?: number;
ver?: number;
zoneinfo?: string;
at_hash?: string;
acr?: string;
};
I tried to use module augmentation in TypeScript to overrride the claims
prop on the AccessToken
interface, but it’s complaining that Subsequent property declarations must have the same type. Property 'claims' must be of type 'UserClaims', but here has type 'UserClaims<{ firstName: string; lastName: string; }>'
. My module augmentation looks like:
import "@okta/okta-auth-js";
import { UserClaims } from "@okta/okta-auth-js";
declare module "@okta/okta-auth-js" {
interface AccessToken {
claims: UserClaims<{ firstName: string; lastName: string }>;
}
}
I can of course force the type conversion where I access the claims, but I was hoping to clearly define those claims for the next person.
Am I just doing something wrong? any recommendation how to properly type those access token claims?