You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.4 KiB
64 lines
2.4 KiB
using Easy.Options;
|
|
using IdentityServer.EF;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
namespace IdentityServer.Realization;
|
|
|
|
public static class CustomExtension
|
|
{
|
|
public static void AddCustomIdentityServer(this WebApplicationBuilder builder)
|
|
{
|
|
var identityServerBuilder = builder.Services.AddIdentityServer(options =>
|
|
{
|
|
options.UserInteraction.LoginUrl = "/login";
|
|
options.UserInteraction.ConsentUrl = "/consent";
|
|
options.UserInteraction.LogoutUrl = "/logout";
|
|
options.UserInteraction.ErrorUrl = "/error";
|
|
|
|
options.Events.RaiseErrorEvents = true;
|
|
options.Events.RaiseInformationEvents = true;
|
|
options.Events.RaiseFailureEvents = true;
|
|
options.Events.RaiseSuccessEvents = true;
|
|
|
|
// see https://docs.duendesoftware.com/identityserver/v5/fundamentals/resources/
|
|
options.EmitStaticAudienceClaim = true;
|
|
});
|
|
identityServerBuilder.AddInMemoryIdentityResources(SimpleConfig.IdentityResources);
|
|
identityServerBuilder.AddInMemoryApiScopes(SimpleConfig.ApiScopes);
|
|
identityServerBuilder.AddInMemoryClients(SimpleConfig.Clients);
|
|
|
|
identityServerBuilder.AddProfileService<CustomProfileService>();
|
|
}
|
|
//public static void AddCustomAuthentication(this WebApplicationBuilder builder)
|
|
//{
|
|
// builder.Services.AddAuthentication("Bearer")
|
|
// .AddJwtBearer("Bearer", options =>
|
|
// {
|
|
// options.Authority = "";
|
|
|
|
// options.TokenValidationParameters = new TokenValidationParameters
|
|
// {
|
|
// ValidateAudience = false
|
|
// };
|
|
// });
|
|
//}
|
|
public static void AddCustomDbContext(this WebApplicationBuilder builder)
|
|
{
|
|
var sqlConnectionString = builder.Configuration["ConnectionString"];
|
|
|
|
builder.Services.AddDbContext<IdentityContext>(optionsBuilder =>
|
|
{
|
|
if (!string.IsNullOrEmpty(sqlConnectionString))
|
|
{
|
|
optionsBuilder.UseMySql(sqlConnectionString, ServerVersion.Parse("8.0.28-mysql"));
|
|
}
|
|
});
|
|
builder.Services.AddTransient<DbContext, IdentityContext>();
|
|
|
|
builder.Services.Configure<SequentialGuidGeneratorOptions>(options =>
|
|
{
|
|
options.SequentialGuidType = Easy.Enums.SequentialGuidType.SequentialAsString;
|
|
});
|
|
}
|
|
}
|
|
|