Skip to content

Commit c4fe564

Browse files
authored
Simplify OIDC types & export decodeIdToken (#4193)
* Fix types Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Export `decodeIdToken` Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 9ecb1a0 commit c4fe564

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

src/oidc/validate.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import { jwtDecode } from "jwt-decode";
18-
import { OidcMetadata, SigninResponse } from "oidc-client-ts";
18+
import { IdTokenClaims, OidcMetadata, SigninResponse } from "oidc-client-ts";
1919

2020
import { logger } from "../logger";
2121
import { OidcError } from "./error";
@@ -139,28 +139,7 @@ export function isValidatedIssuerMetadata(
139139
validateOIDCIssuerWellKnown(metadata);
140140
}
141141

142-
/**
143-
* Standard JWT claims.
144-
*
145-
* @see https://datatracker.ietf.org/doc/html/rfc7519#section-4.1
146-
*/
147-
interface JwtClaims {
148-
[claim: string]: unknown;
149-
/** The "iss" (issuer) claim identifies the principal that issued the JWT. */
150-
iss?: string;
151-
/** The "sub" (subject) claim identifies the principal that is the subject of the JWT. */
152-
sub?: string;
153-
/** The "aud" (audience) claim identifies the recipients that the JWT is intended for. */
154-
aud?: string | string[];
155-
/** The "exp" (expiration time) claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. */
156-
exp?: number;
157-
// unused claims excluded
158-
}
159-
interface IdTokenClaims extends JwtClaims {
160-
nonce?: string;
161-
}
162-
163-
const decodeIdToken = (token: string): IdTokenClaims => {
142+
export const decodeIdToken = (token: string): IdTokenClaims => {
164143
try {
165144
return jwtDecode<IdTokenClaims>(token);
166145
} catch (error) {
@@ -276,7 +255,7 @@ export type BearerTokenResponse = {
276255
expires_in?: number;
277256
// from oidc-client-ts
278257
expires_at?: number;
279-
id_token?: string;
258+
id_token: string;
280259
};
281260

282261
/**

0 commit comments

Comments
 (0)