load the cert file
This commit is contained in:
parent
04009f99e3
commit
2f645b7f0f
3 changed files with 26 additions and 26 deletions
|
|
@ -130,7 +130,8 @@ public static class HostingExtensions
|
||||||
options.Authority = builder.Configuration.GetSection("Site")["Authority"];
|
options.Authority = builder.Configuration.GetSection("Site")["Authority"];
|
||||||
options.Audience = builder.Configuration.GetSection("Site")["Audience"];
|
options.Audience = builder.Configuration.GetSection("Site")["Audience"];
|
||||||
options.TokenValidationParameters =
|
options.TokenValidationParameters =
|
||||||
new() {
|
new()
|
||||||
|
{
|
||||||
ValidateAudience = false,
|
ValidateAudience = false,
|
||||||
RoleClaimType = Constants.RoleClaimType
|
RoleClaimType = Constants.RoleClaimType
|
||||||
};
|
};
|
||||||
|
|
@ -148,7 +149,7 @@ public static class HostingExtensions
|
||||||
IServiceCollection services = builder.Services;
|
IServiceCollection services = builder.Services;
|
||||||
services.AddDbContext<ApplicationDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
{
|
{
|
||||||
options.UseNpgsql(builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName ),
|
options.UseNpgsql(builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName),
|
||||||
options => options.MigrationsAssembly(typeof(Program).Assembly));
|
options => options.MigrationsAssembly(typeof(Program).Assembly));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -257,6 +258,12 @@ public static class HostingExtensions
|
||||||
}
|
}
|
||||||
private static IIdentityServerBuilder AddIdentityServer(WebApplicationBuilder builder)
|
private static IIdentityServerBuilder AddIdentityServer(WebApplicationBuilder builder)
|
||||||
{
|
{
|
||||||
|
builder.Services.Configure<IdentityOptions>(options =>
|
||||||
|
{
|
||||||
|
options.ClaimsIdentity.UserIdClaimType = JwtClaimTypes.Subject;
|
||||||
|
options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.Name;
|
||||||
|
options.ClaimsIdentity.RoleClaimType = Constants.RoleClaimType;
|
||||||
|
});
|
||||||
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
|
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
|
||||||
var connectionString = builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName);
|
var connectionString = builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName);
|
||||||
|
|
||||||
|
|
@ -289,33 +296,10 @@ public static class HostingExtensions
|
||||||
sql => sql.MigrationsAssembly(migrationsAssembly));
|
sql => sql.MigrationsAssembly(migrationsAssembly));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
builder.Services.Configure<IdentityOptions>(options =>
|
|
||||||
{
|
|
||||||
options.ClaimsIdentity.UserIdClaimType = JwtClaimTypes.Subject;
|
|
||||||
options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.Name;
|
|
||||||
options.ClaimsIdentity.RoleClaimType = Constants.RoleClaimType;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (builder.Environment.IsDevelopment())
|
if (builder.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
identityServerBuilder.AddDeveloperSigningCredential();
|
identityServerBuilder.AddDeveloperSigningCredential();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
var path = builder.Configuration["SigningCert:Path"];
|
|
||||||
if (path == null)
|
|
||||||
throw new InvalidConfigurationException("No signing cert path");
|
|
||||||
FileInfo certFileInfo = new FileInfo(path);
|
|
||||||
Debug.Assert(certFileInfo.Exists);
|
|
||||||
RSA rsa = RSA.Create();
|
|
||||||
rsa.ImportFromPem(File.ReadAllText(certFileInfo.FullName));
|
|
||||||
var signingCredentials = new SigningCredentials(new RsaSecurityKey(rsa), SecurityAlgorithms.RsaSha256)
|
|
||||||
{
|
|
||||||
CryptoProviderFactory = new CryptoProviderFactory { CacheSignatureProviders = false }
|
|
||||||
};
|
|
||||||
identityServerBuilder.AddSigningCredential(signingCredentials);
|
|
||||||
}
|
|
||||||
return identityServerBuilder;
|
return identityServerBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
16
test/yavscTests/Mandatory/Services.cs
Normal file
16
test/yavscTests/Mandatory/Services.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
using isnd.tests;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace yavscTests.Mandatory;
|
||||||
|
|
||||||
|
[Collection("Yavsc Server")]
|
||||||
|
[Trait("regression", "oui")]
|
||||||
|
public class Services : BaseTestContext, IClassFixture<WebServerFixture>
|
||||||
|
{
|
||||||
|
public Services(ITestOutputHelper output, WebServerFixture fixture) : base(output, fixture)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -31,4 +31,4 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Using Include="Xunit" />
|
<Using Include="Xunit" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue