New Angular based web version #1
@@ -6,11 +6,9 @@ public class JwtOptions
|
||||
{
|
||||
public const string SectionName = "JWT";
|
||||
|
||||
public string Audience { get; set; } = "";
|
||||
public string ValidAudience { get; set; } = "";
|
||||
|
||||
public string Authority { get; set; } = "";
|
||||
|
||||
public string Issuer { get; set; } = "";
|
||||
public string MetadataUrl { get; set; } = "";
|
||||
|
||||
public string? NameClaimType { get; set; }
|
||||
}
|
||||
@@ -19,13 +17,10 @@ public class JwtOptionsValidator : AbstractValidator<JwtOptions>
|
||||
{
|
||||
public JwtOptionsValidator()
|
||||
{
|
||||
RuleFor(x => x.Audience)
|
||||
RuleFor(x => x.ValidAudience)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(x => x.Authority)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(x => x.Issuer)
|
||||
RuleFor(x => x.MetadataUrl)
|
||||
.NotEmpty();
|
||||
}
|
||||
}
|
||||
@@ -125,14 +125,11 @@ public static class DependencyInjectionExtensions
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, o =>
|
||||
{
|
||||
o.Authority = jwtOptions.Value.Authority;
|
||||
o.MetadataAddress = jwtOptions.Value.MetadataUrl;
|
||||
|
||||
o.TokenValidationParameters.ValidAudience = jwtOptions.Value.Audience;
|
||||
o.TokenValidationParameters.ValidAudience = jwtOptions.Value.ValidAudience;
|
||||
o.TokenValidationParameters.ValidateAudience = true;
|
||||
|
||||
o.TokenValidationParameters.ValidIssuer = jwtOptions.Value.Issuer;
|
||||
o.TokenValidationParameters.ValidateIssuer = true;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(jwtOptions.Value.NameClaimType))
|
||||
{
|
||||
o.TokenValidationParameters.NameClaimType = jwtOptions.Value.NameClaimType;
|
||||
|
||||
@@ -45,9 +45,8 @@ public sealed class WebAppFactory : WebApplicationFactory<IWebApiMarker>, IAsync
|
||||
IEnumerable<KeyValuePair<string, string?>> customConfig =
|
||||
[
|
||||
new KeyValuePair<string, string?>("ConnectionStrings:Database", _database.GetConnectionString()),
|
||||
new KeyValuePair<string, string?>("JWT:Authority", "https://localhost"),
|
||||
new KeyValuePair<string, string?>("JWT:Audience", "https://localhost"),
|
||||
new KeyValuePair<string, string?>("JWT:Issuer", "https://localhost"),
|
||||
new KeyValuePair<string, string?>("JWT:ValidAudience", "https://localhost"),
|
||||
new KeyValuePair<string, string?>("JWT:MetadataUrl", "https://localhost"),
|
||||
new KeyValuePair<string, string?>("JWT:NameClaimType", null),
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user