@@ -284,6 +284,12 @@ public async Task WhenPostTokenWithValidAuthorizationCode_ShouldReturnAccessToke
284284 Assert . NotEmpty ( clients ) ;
285285 Assert . NotNull ( client ) ;
286286
287+ // arrange: assign client audience
288+ var assignAudience = new AssignClientAudienceScheme { Value = "backend.api" } ;
289+ var assignAudienceResponse = await realmAdminClient . PostAsJsonAsync ( $ "api/v1/clients/{ client . Id } /audiences", assignAudience ) ;
290+
291+ Assert . Equal ( HttpStatusCode . OK , assignAudienceResponse . StatusCode ) ;
292+
287293 // arrange: create user for realm
288294 var credentials = new IdentityEnrollmentCredentials
289295 {
@@ -341,6 +347,7 @@ public async Task WhenPostTokenWithValidAuthorizationCode_ShouldReturnAccessToke
341347 ExpiresAt = DateTime . UtcNow . AddMinutes ( 5 ) ,
342348 Metadata = new Dictionary < string , string >
343349 {
350+ [ "client.id" ] = client . ClientId ,
344351 [ "code.challenge" ] = codeChallenge ,
345352 [ "code.challenge.method" ] = codeChallengeMethod
346353 }
@@ -367,5 +374,15 @@ public async Task WhenPostTokenWithValidAuthorizationCode_ShouldReturnAccessToke
367374 // assert: response should be 200 OK
368375 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
369376 Assert . NotNull ( grant ) ;
377+
378+ var handler = new JwtSecurityTokenHandler ( ) ;
379+ var jwt = handler . ReadJwtToken ( grant . AccessToken ) ;
380+ var audiences = jwt . Claims
381+ . Where ( claim => claim . Type == JwtRegisteredClaimNames . Aud )
382+ . Select ( claim => claim . Value )
383+ . ToList ( ) ;
384+
385+ Assert . Contains ( "backend.api" , audiences ) ;
386+ Assert . DoesNotContain ( realm . Name , audiences ) ;
370387 }
371388}
0 commit comments