1- import { browser , dev } from '$app/environment' ;
1+ import { dev } from '$app/environment' ;
22import { env } from '$env/dynamic/private' ;
33import type { MaybeToken , Rule } from '$lib/types/oidc' ;
44import { type Cookies , type RequestEvent } from '@sveltejs/kit' ;
@@ -51,10 +51,18 @@ function getSupportedAlgorithms(): jwt.Algorithm[] {
5151 * - Your IdP's token mapper configuration
5252 */
5353export const CLAIMS_CONFIG = {
54- get namespace ( ) { return env . OIDC_CLAIMS_NAMESPACE || 'https://hasura.io/jwt/claims' ; } ,
55- get userId ( ) { return env . OIDC_CLAIMS_USER_ID || 'x-hasura-user-id' ; } ,
56- get allowedRoles ( ) { return env . OIDC_CLAIMS_ALLOWED_ROLES || 'x-hasura-allowed-roles' ; } ,
57- get defaultRole ( ) { return env . OIDC_CLAIMS_DEFAULT_ROLE || 'x-hasura-default-role' ; } ,
54+ get allowedRoles ( ) {
55+ return env . OIDC_CLAIMS_ALLOWED_ROLES || 'x-hasura-allowed-roles' ;
56+ } ,
57+ get defaultRole ( ) {
58+ return env . OIDC_CLAIMS_DEFAULT_ROLE || 'x-hasura-default-role' ;
59+ } ,
60+ get namespace ( ) {
61+ return env . OIDC_CLAIMS_NAMESPACE || 'https://hasura.io/jwt/claims' ;
62+ } ,
63+ get userId ( ) {
64+ return env . OIDC_CLAIMS_USER_ID || 'x-hasura-user-id' ;
65+ } ,
5866} ;
5967
6068/**
@@ -66,9 +74,9 @@ export const CLAIMS_CONFIG = {
6674 * @throws Error if required claims are missing
6775 */
6876export function extractClaims ( token : jwt . JwtPayload ) : {
69- userId : string ;
7077 allowedRoles : string [ ] ;
7178 defaultRole : string ;
79+ userId : string ;
7280} {
7381 const namespace = token [ CLAIMS_CONFIG . namespace ] ;
7482 if ( ! namespace || typeof namespace !== 'object' ) {
@@ -88,10 +96,12 @@ export function extractClaims(token: jwt.JwtPayload): {
8896 ) ;
8997 }
9098 if ( ! defaultRole || typeof defaultRole !== 'string' ) {
91- throw new Error ( `JWT missing or invalid default role claim: ${ CLAIMS_CONFIG . namespace } .${ CLAIMS_CONFIG . defaultRole } ` ) ;
99+ throw new Error (
100+ `JWT missing or invalid default role claim: ${ CLAIMS_CONFIG . namespace } .${ CLAIMS_CONFIG . defaultRole } ` ,
101+ ) ;
92102 }
93103
94- return { userId , allowedRoles, defaultRole } ;
104+ return { allowedRoles, defaultRole, userId } ;
95105}
96106
97107/**
@@ -240,8 +250,8 @@ export function verifyNonce(idToken: string, expectedNonce: string): void {
240250 *
241251 */
242252export class Client {
243- private static _instance : Client ;
244253 private static _initPromise : Promise < Client > ;
254+ private static _instance : Client ;
245255
246256 private authorizationEndpoint ! : string ;
247257 private client ! : arctic . OAuth2Client ;
0 commit comments