|
|
|
@ -3,11 +3,13 @@ using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Cors;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
|
using MyCompanyName.MyProjectName.EntityFrameworkCore;
|
|
|
|
|
using MyCompanyName.MyProjectName.MultiTenancy;
|
|
|
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
|
|
|
|
@ -25,6 +27,8 @@ using Volo.Abp.AspNetCore.Serilog;
|
|
|
|
|
using Volo.Abp.Autofac;
|
|
|
|
|
using Volo.Abp.Localization;
|
|
|
|
|
using Volo.Abp.Modularity;
|
|
|
|
|
using Volo.Abp.OpenIddict;
|
|
|
|
|
using Volo.Abp.OpenIddict.WildcardDomains;
|
|
|
|
|
using Volo.Abp.Swashbuckle;
|
|
|
|
|
using Volo.Abp.UI.Navigation.Urls;
|
|
|
|
|
using Volo.Abp.VirtualFileSystem;
|
|
|
|
@ -39,12 +43,39 @@ namespace MyCompanyName.MyProjectName;
|
|
|
|
|
typeof(MyProjectNameEntityFrameworkCoreModule),
|
|
|
|
|
typeof(AbpAspNetCoreMvcUiBasicThemeModule),
|
|
|
|
|
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
|
|
|
|
|
typeof(AbpAccountWebIdentityServerModule),
|
|
|
|
|
typeof(AbpAccountWebOpenIddictModule),
|
|
|
|
|
typeof(AbpAspNetCoreSerilogModule),
|
|
|
|
|
typeof(AbpSwashbuckleModule)
|
|
|
|
|
)]
|
|
|
|
|
public class MyProjectNameHttpApiHostModule : AbpModule
|
|
|
|
|
{
|
|
|
|
|
public override void PreConfigureServices(ServiceConfigurationContext context)
|
|
|
|
|
{
|
|
|
|
|
PreConfigure<OpenIddictServerBuilder>(builder =>
|
|
|
|
|
{
|
|
|
|
|
//https://documentation.openiddict.com/configuration/token-formats.html#disabling-jwt-access-token-encryption
|
|
|
|
|
//https://documentation.openiddict.com/configuration/encryption-and-signing-credentials.html
|
|
|
|
|
builder.AddSigningKey(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_C40DBB176E78")));
|
|
|
|
|
builder.AddEncryptionKey(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_87E33FC57D80")));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
PreConfigure<AbpOpenIddictWildcardDomainOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.EnableWildcardDomainSupport = true;
|
|
|
|
|
options.WildcardDomainsFormat.Add("https://{0}.abp.io/signin-oidc");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
PreConfigure<OpenIddictBuilder>(builder =>
|
|
|
|
|
{
|
|
|
|
|
builder.AddValidation(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddAudiences("MyProjectName");
|
|
|
|
|
options.UseLocalServer();
|
|
|
|
|
options.UseAspNetCore();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
|
|
|
{
|
|
|
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
@ -117,6 +148,11 @@ public class MyProjectNameHttpApiHostModule : AbpModule
|
|
|
|
|
|
|
|
|
|
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
Configure<AbpOpenIddictAspNetCoreOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddDevelopmentEncryptionAndSigningCertificate = false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.Services.AddAuthentication()
|
|
|
|
|
.AddJwtBearer(options =>
|
|
|
|
|
{
|
|
|
|
@ -128,6 +164,9 @@ public class MyProjectNameHttpApiHostModule : AbpModule
|
|
|
|
|
ServerCertificateCustomValidationCallback =
|
|
|
|
|
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_C40DBB176E78"));
|
|
|
|
|
options.TokenValidationParameters.TokenDecryptionKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_87E33FC57D80"));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -144,6 +183,7 @@ public class MyProjectNameHttpApiHostModule : AbpModule
|
|
|
|
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProjectName API", Version = "v1" });
|
|
|
|
|
options.DocInclusionPredicate((docName, description) => true);
|
|
|
|
|
options.CustomSchemaIds(type => type.FullName);
|
|
|
|
|
options.ResolveConflictingActions(x => x.First());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -225,7 +265,6 @@ public class MyProjectNameHttpApiHostModule : AbpModule
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseUnitOfWork();
|
|
|
|
|
app.UseIdentityServer();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|