Skip to content

Commit e850ca8

Browse files
feature(#20): support for multiple audiences in JWT authentication with validation of multiple audiences.
1 parent 7c043ec commit e850ca8

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

Packages/Federation.Sdk/Source/Configurations/FederationOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ public sealed record FederationOptions
66
public string ClientSecret { get; set; } = default!;
77
public string Realm { get; set; } = default!;
88
public string Authority { get; set; } = default!;
9-
}
9+
public string[] Audiences { get; set; } = [];
10+
}

Packages/Federation.Sdk/Source/Extensions/AuthenticationExtension.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ public static void AddBearerAuthentication(this IServiceCollection services)
1111
.AddJwtBearer(configuration =>
1212
{
1313
configuration.Authority = options.Authority;
14-
configuration.Audience = options.Realm;
1514
configuration.RequireHttpsMetadata = false;
15+
configuration.TokenValidationParameters = new TokenValidationParameters
16+
{
17+
ValidateIssuer = true,
18+
ValidateAudience = true,
19+
20+
// https://www.rfc-editor.org/rfc/rfc7519.html?#section-4.1.3
21+
// supports multiple audiences in the "aud" claim, so we need to check if any of the audiences match
22+
ValidIssuer = options.Authority,
23+
ValidAudiences = options.Audiences
24+
};
1625
});
1726
}
18-
}
27+
}

0 commit comments

Comments
 (0)