@@ -230,14 +230,18 @@ describe('tokens.verifyMachineAuthToken(token, options)', () => {
230230 expect ( data . scopes ) . toEqual ( [ 'mch_1xxxxx' , 'mch_2xxxxx' ] ) ;
231231 } ) ;
232232
233- it ( 'verifies provided OAuth token' , async ( ) => {
233+ it . each ( [
234+ { aud : undefined } ,
235+ { aud : 'https://my-resource.example.com' } ,
236+ { aud : [ 'https://my-resource.example.com' , 'https://other-resource.example.com' ] } ,
237+ ] ) ( 'verifies opaque OAuth token with aud=$aud' , async ( { aud } ) => {
234238 const token = 'oat_8XOIucKvqHVr5tYP123456789abcdefghij' ;
235239
236240 server . use (
237241 http . post (
238242 'https://api.clerk.test/oauth_applications/access_tokens/verify' ,
239243 validateHeaders ( ( ) => {
240- return HttpResponse . json ( mockVerificationResults . oauth_token ) ;
244+ return HttpResponse . json ( { ... mockVerificationResults . oauth_token , ... ( aud === undefined ? { } : { aud } ) } ) ;
241245 } ) ,
242246 ) ,
243247 ) ;
@@ -255,6 +259,7 @@ describe('tokens.verifyMachineAuthToken(token, options)', () => {
255259 expect ( data . id ) . toBe ( 'oat_2VTWUzvGC5UhdJCNx6xG1D98edc' ) ;
256260 expect ( data . subject ) . toBe ( 'user_2vYVtestTESTtestTESTtestTESTtest' ) ;
257261 expect ( data . scopes ) . toEqual ( [ 'read:foo' , 'write:bar' ] ) ;
262+ expect ( data . aud ) . toEqual ( aud ) ;
258263 } ) ;
259264
260265 describe ( 'handles API errors for API keys' , ( ) => {
@@ -424,6 +429,7 @@ describe('tokens.verifyMachineAuthToken(token, options)', () => {
424429 expect ( data . type ) . toBe ( 'oauth_token' ) ;
425430 expect ( data . subject ) . toBe ( 'user_2vYVtestTESTtestTESTtestTESTtest' ) ;
426431 expect ( data . scopes ) . toEqual ( [ 'read:foo' , 'write:bar' ] ) ;
432+ expect ( data . aud ) . toBeUndefined ( ) ;
427433 // Timestamps are exposed in milliseconds, matching M2MToken and the API JSON shape
428434 expect ( data . expiration ) . toBe ( mockOAuthAccessTokenJwtPayload . exp * 1000 ) ;
429435 expect ( data . createdAt ) . toBe ( mockOAuthAccessTokenJwtPayload . iat * 1000 ) ;
@@ -570,7 +576,10 @@ describe('tokens.verifyMachineAuthToken(token, options)', () => {
570576 } ,
571577 ) ;
572578
573- it ( 'verifies OAuth JWT with a matching RFC 8707 resource audience' , async ( ) => {
579+ it . each ( [
580+ { aud : 'https://my-resource.example.com' } ,
581+ { aud : [ 'https://my-resource.example.com' , 'https://other-resource.example.com' ] } ,
582+ ] ) ( 'verifies OAuth JWT with a matching resource audience aud=$aud' , async ( { aud } ) => {
574583 server . use (
575584 http . get (
576585 'https://api.clerk.test/v1/jwks' ,
@@ -583,7 +592,7 @@ describe('tokens.verifyMachineAuthToken(token, options)', () => {
583592 const audience = 'https://my-resource.example.com' ;
584593 const oauthJwt = await createSignedOAuthJwt ( {
585594 ...mockOAuthAccessTokenJwtPayload ,
586- aud : audience ,
595+ aud,
587596 } ) ;
588597
589598 const result = await verifyMachineAuthToken ( oauthJwt , {
@@ -593,26 +602,7 @@ describe('tokens.verifyMachineAuthToken(token, options)', () => {
593602 } ) ;
594603
595604 expect ( result . tokenType ) . toBe ( 'oauth_token' ) ;
596- expect ( result . data ) . toMatchInlineSnapshot ( `
597- IdPOAuthAccessToken {
598- "aud": "https://my-resource.example.com",
599- "clientId": "client_2VTWUzvGC5UhdJCNx6xG1D98edc",
600- "createdAt": 1666648250000,
601- "expiration": 1666648550000,
602- "expired": false,
603- "id": "oat_2xKa9Bgv7NxMRDFyQw8LpZ3cTmU1vHjE",
604- "revocationReason": null,
605- "revoked": false,
606- "scopes": [
607- "read:foo",
608- "write:bar",
609- ],
610- "subject": "user_2vYVtestTESTtestTESTtestTESTtest",
611- "type": "oauth_token",
612- "updatedAt": 1666648250000,
613- }
614- ` ) ;
615- expect ( ( result . data as IdPOAuthAccessToken ) . aud ) . toBe ( audience ) ;
605+ expect ( result . data ) . toMatchObject ( { aud, scopes : [ 'read:foo' , 'write:bar' ] } ) ;
616606 expect ( result . errors ) . toBeUndefined ( ) ;
617607 } ) ;
618608
0 commit comments