filterProtocolClaims deletes properties required by the IdTokenClaims type
See original GitHub issueIf filterProtocolClaims is set to true (the default), the properties iss
, aud
, exp
and iat
that are required by the IdTokenClaims type are deleted and undefined, thus breaking the defined types.
const userManager = new UserManager({
// ... other options omitted
filterProtocolClaims: true, // defaults to true
// ...
});
const user = await userManager.getUser();
const exp = user.profile.exp; // TypeScript says this is a number
console.log(typeof exp) // Should be "number" but is "undefined"
Relevant parts of the code
These properties are deleted from the response: https://github.com/authts/oidc-client-ts/blob/bcfe363c685e8f243b43bc588ecba7495f88ffa9/src/ResponseValidator.ts#L26-L41 https://github.com/authts/oidc-client-ts/blob/bcfe363c685e8f243b43bc588ecba7495f88ffa9/src/ResponseValidator.ts#L225-L235 Some of which are mandatory here: https://github.com/authts/oidc-client-ts/blob/bcfe363c685e8f243b43bc588ecba7495f88ffa9/src/Claims.ts#L109
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Issues · authts/oidc-client-ts
filterProtocolClaims deletes properties required by the IdTokenClaims type bug Something isn't working help wanted Extra attention is needed.
Read more >@azure/msal-common | microsoft-authentication-libraries-for-js
idTokenClaims - Object contains claims from ID token; localAccountId - The user's account ID; nativeAccountId - The user's native account ID ...
Read more >Provide optional claims to Azure AD apps - Microsoft Entra
An application can configure optional claims to be returned in each of three types of tokens (ID token, access token, SAML 2 token)...
Read more >OpenID Connect & OAuth 2.0 API
Find information about the OAuth 2.0 and OpenID Connect endpoints that Okta exposes on its authorization servers.
Read more >Authts Oidc-Client-Ts Statistics & Issues - Codesti
Issue Title State Comments Created Date Updated Date
AWS Cognito ‑ got it working open 0 2022‑12‑15 2022‑12‑12
Using package with Vite and Pinia closed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
userManager.getUser().profile
property is of typeUserProfile
and equals toIdTokenClaims
: https://github.com/authts/oidc-client-ts/blob/bcfe363c685e8f243b43bc588ecba7495f88ffa9/src/User.ts#L11IdTokenClaims
requiresiss, sub, aud, exp, iat
to be mandatory as per the OIDC specs, and any other properties are optionals: https://github.com/authts/oidc-client-ts/blob/bcfe363c685e8f243b43bc588ecba7495f88ffa9/src/Claims.ts#L103-L109So I think those 5 should never be deleted no matter what (even to reduce storage space).
We could simply modify
ProtocolClaims
like this:But beyond that, I don’t like the idea that a user could be biased because of the filtering process. (ie. a user may receive an
undefined
property that isdefined
but wasdeleted
) So if we want to keep it that way, we will also have to reduce the scope ofUserProfile
(something likeUserProfile = Omit<IdTokenClaims, keyof ProtocolClaims>
)or… drop the filtering completely as suggested by @pamapa.
@brockallen @pamapa My use case is that I use them for informational/debugging purposes, for example printing the time of issue, which I can do just fine by disabling the filter, so it’s beside the point I’m trying to make. This issue is about the type being incorrect. If the properties are not guaranteed to be defined, they must be typed as optional, simple as that.