@@ -424,6 +424,49 @@ describe('createPrivateKeyJwtAuth', () => {
424424 / K e y f o r t h e R S 2 5 6 a l g o r i t h m m u s t b e o n e o f t y p e C r y p t o K e y , K e y O b j e c t , o r J S O N W e b K e y /
425425 ) ;
426426 } ) ;
427+
428+ it ( 'includes custom claims in the signed JWT assertion' , async ( ) => {
429+ const addClientAuth = createPrivateKeyJwtAuth ( {
430+ issuer : 'client-id' ,
431+ subject : 'client-id' ,
432+ privateKey : 'a-string-secret-at-least-256-bits-long' ,
433+ alg : 'HS256' ,
434+ claims : { tenant_id : 'org-123' , role : 'admin' }
435+ } ) ;
436+
437+ const params = new URLSearchParams ( ) ;
438+ await addClientAuth ( new Headers ( ) , params , 'https://auth.example.com/token' , undefined ) ;
439+
440+ const assertion = params . get ( 'client_assertion' ) ;
441+ expect ( assertion ) . toBeTruthy ( ) ;
442+
443+ const jose = await import ( 'jose' ) ;
444+ const decoded = jose . decodeJwt ( assertion ! ) ;
445+ expect ( decoded . tenant_id ) . toBe ( 'org-123' ) ;
446+ expect ( decoded . role ) . toBe ( 'admin' ) ;
447+ expect ( decoded . iss ) . toBe ( 'client-id' ) ;
448+ expect ( decoded . sub ) . toBe ( 'client-id' ) ;
449+ } ) ;
450+
451+ it ( 'passes custom claims through PrivateKeyJwtProvider' , async ( ) => {
452+ const provider = new PrivateKeyJwtProvider ( {
453+ clientId : 'client-id' ,
454+ privateKey : 'a-string-secret-at-least-256-bits-long' ,
455+ algorithm : 'HS256' ,
456+ claims : { tenant_id : 'org-456' }
457+ } ) ;
458+
459+ const params = new URLSearchParams ( ) ;
460+ await provider . addClientAuthentication ( new Headers ( ) , params , 'https://auth.example.com/token' , undefined ) ;
461+
462+ const assertion = params . get ( 'client_assertion' ) ;
463+ expect ( assertion ) . toBeTruthy ( ) ;
464+
465+ const jose = await import ( 'jose' ) ;
466+ const decoded = jose . decodeJwt ( assertion ! ) ;
467+ expect ( decoded . tenant_id ) . toBe ( 'org-456' ) ;
468+ expect ( decoded . iss ) . toBe ( 'client-id' ) ;
469+ } ) ;
427470} ) ;
428471
429472describe ( 'CrossAppAccessProvider' , ( ) => {
0 commit comments