wanggang
1 year ago
19 changed files with 838 additions and 99 deletions
@ -1,5 +1,5 @@ |
|||
export default { |
|||
enableLocale: false, |
|||
baseURL: "http://dev.ccwin-in.com:10582/api", |
|||
//baseURL: "http://localhost:10130/api",
|
|||
//baseURL: "http://dev.ccwin-in.com:10582/api",
|
|||
baseURL: "http://localhost:44378/api", |
|||
}; |
|||
|
@ -0,0 +1 @@ |
|||
wwwroot/files/ |
@ -0,0 +1,255 @@ |
|||
using IdentityServer4.Models; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.Identity; |
|||
using Volo.Abp.IdentityServer.ApiResources; |
|||
using Volo.Abp.IdentityServer.ApiScopes; |
|||
using Volo.Abp.IdentityServer.Clients; |
|||
using Volo.Abp.IdentityServer.IdentityResources; |
|||
using Volo.Abp.PermissionManagement; |
|||
using Volo.Abp.Uow; |
|||
using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; |
|||
using ApiScope = Volo.Abp.IdentityServer.ApiScopes.ApiScope; |
|||
using Client = Volo.Abp.IdentityServer.Clients.Client; |
|||
|
|||
namespace AuthServer.Host |
|||
{ |
|||
public class AuthServerDataSeeder : IDataSeedContributor, ITransientDependency |
|||
{ |
|||
private readonly IApiResourceRepository _apiResourceRepository; |
|||
private readonly IApiScopeRepository _apiScopeRepository; |
|||
private readonly IClientRepository _clientRepository; |
|||
private readonly IIdentityResourceDataSeeder _identityResourceDataSeeder; |
|||
private readonly IGuidGenerator _guidGenerator; |
|||
private readonly IPermissionDataSeeder _permissionDataSeeder; |
|||
|
|||
public AuthServerDataSeeder( |
|||
IClientRepository clientRepository, |
|||
IApiResourceRepository apiResourceRepository, |
|||
IApiScopeRepository apiScopeRepository, |
|||
IIdentityResourceDataSeeder identityResourceDataSeeder, |
|||
IGuidGenerator guidGenerator, |
|||
IPermissionDataSeeder permissionDataSeeder) |
|||
{ |
|||
_clientRepository = clientRepository; |
|||
_apiResourceRepository = apiResourceRepository; |
|||
_apiScopeRepository = apiScopeRepository; |
|||
_identityResourceDataSeeder = identityResourceDataSeeder; |
|||
_guidGenerator = guidGenerator; |
|||
_permissionDataSeeder = permissionDataSeeder; |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
await _identityResourceDataSeeder.CreateStandardResourcesAsync(); |
|||
await CreateApiResourcesAsync(); |
|||
await CreateApiScopesAsync(); |
|||
await CreateClientsAsync(); |
|||
} |
|||
|
|||
private async Task CreateApiScopesAsync() |
|||
{ |
|||
await CreateApiScopeAsync("BaseService"); |
|||
await CreateApiScopeAsync("InternalGateway"); |
|||
await CreateApiScopeAsync("WebAppGateway"); |
|||
await CreateApiScopeAsync("TenantService"); |
|||
await CreateApiScopeAsync("BusinessService"); |
|||
await CreateApiScopeAsync("FileStorageService"); |
|||
await CreateApiScopeAsync("IdentityService"); |
|||
await CreateApiScopeAsync("SettleAccount"); |
|||
} |
|||
|
|||
private async Task CreateApiResourcesAsync() |
|||
{ |
|||
var commonApiUserClaims = new[] |
|||
{ |
|||
"email", |
|||
"email_verified", |
|||
"name", |
|||
"user_name", |
|||
"phone_number", |
|||
"phone_number_verified", |
|||
"role" |
|||
}; |
|||
await CreateApiResourceAsync("IdentityService", commonApiUserClaims); |
|||
await CreateApiResourceAsync("BaseService", commonApiUserClaims); |
|||
await CreateApiResourceAsync("InternalGateway", commonApiUserClaims); |
|||
await CreateApiResourceAsync("WebAppGateway", commonApiUserClaims); |
|||
await CreateApiResourceAsync("TenantService", commonApiUserClaims); |
|||
await CreateApiResourceAsync("BusinessService", commonApiUserClaims); |
|||
await CreateApiResourceAsync("FileStorageService", commonApiUserClaims); |
|||
await CreateApiResourceAsync("SettleAccount", commonApiUserClaims); |
|||
} |
|||
|
|||
private async Task<ApiResource> CreateApiResourceAsync(string name, IEnumerable<string> claims) |
|||
{ |
|||
var apiResource = await _apiResourceRepository.FindByNameAsync(name); |
|||
if (apiResource == null) |
|||
{ |
|||
apiResource = await _apiResourceRepository.InsertAsync( |
|||
new ApiResource( |
|||
_guidGenerator.Create(), |
|||
name, |
|||
name + " API" |
|||
), |
|||
autoSave: true |
|||
); |
|||
} |
|||
|
|||
foreach (var claim in claims) |
|||
{ |
|||
if (apiResource.FindClaim(claim) == null) |
|||
{ |
|||
apiResource.AddUserClaim(claim); |
|||
} |
|||
} |
|||
|
|||
return await _apiResourceRepository.UpdateAsync(apiResource); |
|||
} |
|||
|
|||
private async Task<ApiScope> CreateApiScopeAsync(string name) |
|||
{ |
|||
var apiScope = await _apiScopeRepository.GetByNameAsync(name); |
|||
if (apiScope == null) |
|||
{ |
|||
apiScope = await _apiScopeRepository.InsertAsync( |
|||
new ApiScope( |
|||
_guidGenerator.Create(), |
|||
name, |
|||
name + " API" |
|||
), |
|||
autoSave: true |
|||
); |
|||
} |
|||
|
|||
return apiScope; |
|||
} |
|||
|
|||
private async Task CreateClientsAsync() |
|||
{ |
|||
var commonScopes = new[] |
|||
{ |
|||
"email", |
|||
"username", |
|||
"name", |
|||
"openid", |
|||
"profile", |
|||
"role", |
|||
"phone", |
|||
"address" |
|||
}; |
|||
|
|||
await CreateClientAsync( |
|||
"basic-web", |
|||
new[] { "IdentityService", "BaseService", "WebAppGateway", "FileStorageService", "TenantService", "BusinessService", "SettleAccount" }, |
|||
new[] { "password" }, |
|||
"1q2w3e*".Sha256() |
|||
); |
|||
|
|||
//BaseDataService
|
|||
await CreateClientAsync( |
|||
"business-app", |
|||
new[] { "InternalGateway", "IdentityService", "BaseService", "FileStorageService", "SettleAccount" }, |
|||
new[] { "client_credentials" }, |
|||
"1q2w3e*".Sha256(), |
|||
permissions: new[] { IdentityPermissions.Users.Default } |
|||
); |
|||
//FileStorge
|
|||
await CreateClientAsync( |
|||
"file-app", |
|||
new[] { "InternalGateway", "IdentityService", "BaseService", "BaseDataService", "BusinessService" }, |
|||
new[] { "client_credentials" }, |
|||
"1q2w3e*".Sha256(), |
|||
permissions: new[] { IdentityPermissions.Users.Default } |
|||
); |
|||
} |
|||
|
|||
private async Task<Client> CreateClientAsync( |
|||
string name, |
|||
IEnumerable<string> scopes, |
|||
IEnumerable<string> grantTypes, |
|||
string secret, |
|||
string redirectUri = null, |
|||
string postLogoutRedirectUri = null, |
|||
IEnumerable<string> permissions = null) |
|||
{ |
|||
var client = await _clientRepository.FindByClientIdAsync(name); |
|||
if (client == null) |
|||
{ |
|||
client = await _clientRepository.InsertAsync( |
|||
new Client( |
|||
_guidGenerator.Create(), |
|||
name |
|||
) |
|||
{ |
|||
ClientName = name, |
|||
ProtocolType = "oidc", |
|||
Description = name, |
|||
AlwaysIncludeUserClaimsInIdToken = true, |
|||
AllowOfflineAccess = true, |
|||
AbsoluteRefreshTokenLifetime = 31536000, //365 days
|
|||
AccessTokenLifetime = 31536000, //365 days
|
|||
AuthorizationCodeLifetime = 300, |
|||
IdentityTokenLifetime = 300, |
|||
RequireConsent = false |
|||
}, |
|||
autoSave: true |
|||
); |
|||
} |
|||
|
|||
foreach (var scope in scopes) |
|||
{ |
|||
if (client.FindScope(scope) == null) |
|||
{ |
|||
client.AddScope(scope); |
|||
} |
|||
} |
|||
|
|||
foreach (var grantType in grantTypes) |
|||
{ |
|||
if (client.FindGrantType(grantType) == null) |
|||
{ |
|||
client.AddGrantType(grantType); |
|||
} |
|||
} |
|||
|
|||
if (client.FindSecret(secret) == null) |
|||
{ |
|||
client.AddSecret(secret); |
|||
} |
|||
|
|||
if (redirectUri != null) |
|||
{ |
|||
if (client.FindRedirectUri(redirectUri) == null) |
|||
{ |
|||
client.AddRedirectUri(redirectUri); |
|||
} |
|||
} |
|||
|
|||
if (postLogoutRedirectUri != null) |
|||
{ |
|||
if (client.FindPostLogoutRedirectUri(postLogoutRedirectUri) == null) |
|||
{ |
|||
client.AddPostLogoutRedirectUri(postLogoutRedirectUri); |
|||
} |
|||
} |
|||
|
|||
if (permissions != null) |
|||
{ |
|||
await _permissionDataSeeder.SeedAsync( |
|||
ClientPermissionValueProvider.ProviderName, |
|||
name, |
|||
permissions |
|||
); |
|||
} |
|||
|
|||
return await _clientRepository.UpdateAsync(client); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,125 @@ |
|||
using AuthServer.Host.EntityFrameworkCore; |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Cors; |
|||
using Microsoft.AspNetCore.DataProtection; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using StackExchange.Redis; |
|||
using System; |
|||
using System.Linq; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Account; |
|||
using Volo.Abp.Account.Web; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; |
|||
using Volo.Abp.Auditing; |
|||
using Volo.Abp.AuditLogging.EntityFrameworkCore; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore.SqlServer; |
|||
using Volo.Abp.Identity.EntityFrameworkCore; |
|||
using Volo.Abp.IdentityServer.EntityFrameworkCore; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
|||
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
|||
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace AuthServer.Host |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
|||
typeof(AbpAuditLoggingEntityFrameworkCoreModule), |
|||
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
|||
typeof(AbpIdentityEntityFrameworkCoreModule), |
|||
typeof(AbpIdentityServerEntityFrameworkCoreModule), |
|||
typeof(AbpTenantManagementEntityFrameworkCoreModule), |
|||
typeof(AbpEntityFrameworkCoreSqlServerModule), |
|||
typeof(AbpAccountWebIdentityServerModule), |
|||
typeof(AbpAccountApplicationModule), |
|||
typeof(AbpAspNetCoreMvcUiBasicThemeModule) |
|||
)] |
|||
public class AuthServerHostModule : AbpModule |
|||
{ |
|||
private const string DefaultCorsPolicyName = "Default"; |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
var configuration = context.Services.GetConfiguration(); |
|||
|
|||
context.Services.AddAbpDbContext<AuthServerDbContext>(options => |
|||
{ |
|||
options.AddDefaultRepositories(); |
|||
}); |
|||
|
|||
Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.UseSqlServer(); |
|||
}); |
|||
|
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
|||
}); |
|||
|
|||
context.Services.AddStackExchangeRedisCache(options => |
|||
{ |
|||
options.Configuration = configuration["Redis:Configuration"]; |
|||
}); |
|||
|
|||
context.Services.AddCors(options => |
|||
{ |
|||
options.AddPolicy(DefaultCorsPolicyName, |
|||
builder => |
|||
{ |
|||
builder.WithOrigins(configuration["App:CorsOrigins"] |
|||
.Split(",", StringSplitOptions.RemoveEmptyEntries) |
|||
.Select(o => o.RemovePostFix("/")) |
|||
.ToArray()) |
|||
.WithAbpExposedHeaders() |
|||
.SetIsOriginAllowedToAllowWildcardSubdomains() |
|||
.AllowAnyHeader() |
|||
.AllowAnyMethod() |
|||
.AllowCredentials(); |
|||
}); |
|||
}); |
|||
|
|||
Configure<AbpAuditingOptions>(options => |
|||
{ |
|||
options.IsEnabledForGetRequests = true; |
|||
options.ApplicationName = "AuthServer"; |
|||
}); |
|||
|
|||
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
|||
context.Services.AddDataProtection() |
|||
.PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); |
|||
} |
|||
|
|||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
var app = context.GetApplicationBuilder(); |
|||
|
|||
app.UseCorrelationId(); |
|||
app.UseVirtualFiles(); |
|||
app.UseRouting(); |
|||
app.UseCors(DefaultCorsPolicyName); |
|||
app.UseAuthentication(); |
|||
app.UseMultiTenancy(); |
|||
app.UseIdentityServer(); |
|||
app.UseAuthorization(); |
|||
app.UseAbpRequestLocalization(); |
|||
app.UseAuditing(); |
|||
|
|||
AsyncHelper.RunSync(async () => |
|||
{ |
|||
using (var scope = context.ServiceProvider.CreateScope()) |
|||
{ |
|||
await scope.ServiceProvider |
|||
.GetRequiredService<IDataSeeder>() |
|||
.SeedAsync(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,22 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.IdentityServer.EntityFrameworkCore; |
|||
|
|||
namespace AuthServer.Host.EntityFrameworkCore |
|||
{ |
|||
public class AuthServerDbContext : AbpDbContext<AuthServerDbContext> |
|||
{ |
|||
public AuthServerDbContext(DbContextOptions<AuthServerDbContext> options) |
|||
: base(options) |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected override void OnModelCreating(ModelBuilder modelBuilder) |
|||
{ |
|||
base.OnModelCreating(modelBuilder); |
|||
|
|||
modelBuilder.ConfigureIdentityServer(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
using System.IO; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Design; |
|||
using Microsoft.Extensions.Configuration; |
|||
|
|||
namespace AuthServer.Host.EntityFrameworkCore |
|||
{ |
|||
public class AuthServerDbContextFactory : IDesignTimeDbContextFactory<AuthServerDbContext> |
|||
{ |
|||
public AuthServerDbContext CreateDbContext(string[] args) |
|||
{ |
|||
var configuration = BuildConfiguration(); |
|||
|
|||
var builder = new DbContextOptionsBuilder<AuthServerDbContext>() |
|||
.UseSqlServer(configuration.GetConnectionString("Default")); |
|||
|
|||
return new AuthServerDbContext(builder.Options); |
|||
} |
|||
|
|||
private static IConfigurationRoot BuildConfiguration() |
|||
{ |
|||
var builder = new ConfigurationBuilder() |
|||
.SetBasePath(Directory.GetCurrentDirectory()) |
|||
.AddJsonFile("appsettings.json", optional: false); |
|||
|
|||
return builder.Build(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,274 @@ |
|||
using BaseService.EntityFrameworkCore; |
|||
using Microsoft.AspNetCore.Authentication.JwtBearer; |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Cors; |
|||
using Microsoft.AspNetCore.DataProtection; |
|||
using Microsoft.AspNetCore.Identity; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.OpenApi.Models; |
|||
using StackExchange.Redis; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Security.Claims; |
|||
using Volo.Abp; |
|||
using Volo.Abp.AspNetCore.MultiTenancy; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.AntiForgery; |
|||
using Volo.Abp.AspNetCore.Serilog; |
|||
using Volo.Abp.Auditing; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Identity; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.PermissionManagement.HttpApi; |
|||
using Volo.Abp.Security.Claims; |
|||
using Volo.Abp.TenantManagement; |
|||
using Volo.Abp.Threading; |
|||
|
|||
//using Win.Sfs.SettleAccount;
|
|||
//using Win.Sfs.BaseData;
|
|||
|
|||
//using BaseData;
|
|||
|
|||
namespace BaseService |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpAutofacModule), |
|||
typeof(BaseServiceApplicationModule), |
|||
typeof(BaseServiceEntityFrameworkCoreModule), |
|||
typeof(BaseServiceHttpApiModule), |
|||
typeof(AbpAspNetCoreMultiTenancyModule), |
|||
typeof(AbpPermissionManagementHttpApiModule), |
|||
typeof(AbpTenantManagementHttpApiModule), |
|||
typeof(AbpIdentityHttpApiModule), |
|||
// typeof(BaseDataHttpApiModule),
|
|||
//typeof(BaseDataApplicationContractsModule),
|
|||
//typeof(SettleAccountHttpApiModule),
|
|||
typeof(AbpAspNetCoreSerilogModule) |
|||
)] |
|||
public class BaseServiceHostModule : AbpModule |
|||
{ |
|||
private const string DefaultCorsPolicyName = "Default"; |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddHttpClient(); |
|||
Configure<AbpAntiForgeryOptions>(O => O.AutoValidate = false); |
|||
|
|||
var configuration = context.Services.GetConfiguration(); |
|||
|
|||
ConfigureConventionalControllers(); |
|||
|
|||
ConfigureMultiTenancy(); |
|||
|
|||
ConfigureJwt(context, configuration); |
|||
|
|||
//ConfigureSwagger(context);
|
|||
|
|||
ConfigureDbContext(); |
|||
|
|||
ConfigureRedis(context, configuration); |
|||
|
|||
ConfigureAuditing(); |
|||
|
|||
//ConfigureCros(context, configuration);
|
|||
|
|||
ConfigureLocalization(); |
|||
|
|||
ConfigurePasswordSet(context); |
|||
} |
|||
|
|||
private void ConfigureLocalization() |
|||
{ |
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
|||
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
|||
}); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 设置密码强度
|
|||
/// </summary>
|
|||
/// <param name="context"></param>
|
|||
private void ConfigurePasswordSet(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.Configure<IdentityOptions>(options => |
|||
{ |
|||
options.User.RequireUniqueEmail = true; |
|||
//options.Lockout.AllowedForNewUsers = true;
|
|||
//options.Lockout.MaxFailedAccessAttempts = 2;
|
|||
|
|||
options.Password.RequireDigit = false; |
|||
options.Password.RequireLowercase = false; |
|||
options.Password.RequireNonAlphanumeric = false; |
|||
options.Password.RequireUppercase = false; |
|||
options.Password.RequiredLength = 6; |
|||
}); |
|||
} |
|||
|
|||
private static void ConfigureCros(ServiceConfigurationContext context, IConfiguration configuration) |
|||
{ |
|||
context.Services.AddCors(options => |
|||
{ |
|||
options.AddPolicy(DefaultCorsPolicyName, builder => |
|||
{ |
|||
builder |
|||
.WithOrigins( |
|||
configuration["App:CorsOrigins"] |
|||
.Split(",", StringSplitOptions.RemoveEmptyEntries) |
|||
.Select(o => o.RemovePostFix("/")) |
|||
.ToArray() |
|||
) |
|||
.WithAbpExposedHeaders() |
|||
.SetIsOriginAllowedToAllowWildcardSubdomains() |
|||
.AllowAnyHeader() |
|||
.AllowAnyMethod() |
|||
.AllowCredentials(); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
private void ConfigureAuditing() |
|||
{ |
|||
Configure<AbpAuditingOptions>(options => |
|||
{ |
|||
options.IsEnabledForGetRequests = true; |
|||
options.ApplicationName = "BaseService"; |
|||
}); |
|||
} |
|||
|
|||
private static void ConfigureRedis(ServiceConfigurationContext context, IConfiguration configuration) |
|||
{ |
|||
context.Services.AddStackExchangeRedisCache(options => |
|||
{ |
|||
options.Configuration = configuration["Redis:Configuration"]; |
|||
}); |
|||
|
|||
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
|||
context.Services.AddDataProtection() |
|||
.PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys"); |
|||
} |
|||
|
|||
private void ConfigureDbContext() |
|||
{ |
|||
Configure<AbpDbContextOptions>(options => { options.UseSqlServer(); }); |
|||
} |
|||
|
|||
private static void ConfigureSwagger(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddSwaggerGen(options => |
|||
{ |
|||
options.SwaggerDoc("v1", new OpenApiInfo { Title = "BaseService Service API", Version = "v1" }); |
|||
options.DocInclusionPredicate((docName, description) => true); |
|||
options.CustomSchemaIds(type => type.FullName); |
|||
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
|||
{ |
|||
Description = "请输入 JWT Token", |
|||
Name = "Authorization", |
|||
In = ParameterLocation.Header, |
|||
Type = SecuritySchemeType.Http, |
|||
Scheme = "Bearer" |
|||
}); |
|||
|
|||
options.AddSecurityRequirement(new OpenApiSecurityRequirement() |
|||
{ |
|||
{ |
|||
new OpenApiSecurityScheme |
|||
{ |
|||
Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "Bearer"} |
|||
}, |
|||
new string[] { } |
|||
} |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
private static void ConfigureJwt(ServiceConfigurationContext context, IConfiguration configuration) |
|||
{ |
|||
//context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|||
// .AddJwtBearer(options =>
|
|||
// {
|
|||
// options.Authority = configuration["AuthServer:Authority"];
|
|||
// options.RequireHttpsMetadata = false;
|
|||
// options.Audience = "BaseService";
|
|||
// });
|
|||
} |
|||
|
|||
private void ConfigureMultiTenancy() |
|||
{ |
|||
Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = true; }); |
|||
} |
|||
|
|||
private void ConfigureConventionalControllers() |
|||
{ |
|||
//Configure<AbpAspNetCoreMvcOptions>(options =>
|
|||
//{
|
|||
// options.ConventionalControllers.Create(typeof(BaseServiceApplicationModule).Assembly);
|
|||
//});
|
|||
Configure<AbpAspNetCoreMvcOptions>(options => |
|||
{ |
|||
options |
|||
.ConventionalControllers |
|||
.Create(typeof(BaseServiceApplicationModule).Assembly, opts |
|||
=> |
|||
{ opts.RootPath = "base"; }) |
|||
; |
|||
}); |
|||
} |
|||
|
|||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
var app = context.GetApplicationBuilder(); |
|||
|
|||
app.UseCorrelationId(); |
|||
app.UseVirtualFiles(); |
|||
app.UseRouting(); |
|||
app.UseCors(DefaultCorsPolicyName); |
|||
app.UseAuthentication(); |
|||
app.UseMultiTenancy(); |
|||
|
|||
app.Use(async (ctx, next) => |
|||
{ |
|||
var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService<ICurrentPrincipalAccessor>(); |
|||
var map = new Dictionary<string, string>() |
|||
{ |
|||
{ "sub", AbpClaimTypes.UserId }, |
|||
{ "role", AbpClaimTypes.Role }, |
|||
{ "email", AbpClaimTypes.Email }, |
|||
{ "name", AbpClaimTypes.UserName }, |
|||
}; |
|||
var mapClaims = currentPrincipalAccessor.Principal.Claims.Where(p => map.Keys.Contains(p.Type)).ToList(); |
|||
currentPrincipalAccessor.Principal.AddIdentity(new ClaimsIdentity(mapClaims.Select(p => new Claim(map[p.Type], p.Value, p.ValueType, p.Issuer)))); |
|||
await next(); |
|||
}); |
|||
|
|||
app.UseAbpRequestLocalization(); |
|||
app.UseAuthorization(); |
|||
app.UseSwagger(); |
|||
app.UseSwaggerUI(options => |
|||
{ |
|||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Identity Service API"); |
|||
}); |
|||
|
|||
app.UseAuditing(); |
|||
app.UseAbpSerilogEnrichers(); |
|||
app.UseConfiguredEndpoints(); |
|||
|
|||
AsyncHelper.RunSync(async () => |
|||
{ |
|||
using (var scope = context.ServiceProvider.CreateScope()) |
|||
{ |
|||
await scope.ServiceProvider |
|||
.GetRequiredService<IDataSeeder>() |
|||
.SeedAsync(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
{"AdditionalData":{},"Alg":"RS256","Crv":null,"D":"mkeKcDJDeFxfcUlsAiiqTRAVA5uIhEFm8ZSnSZgYdWCTNs1Yz6fmGcB9rHzoCAhVn3Z3okacYYrQgKTYRr_33iAepQTtwC9IYDOrrBpbKgHI1pYEu7nJGeeYCW_tnUuADV6s8qt5UPUg0HpluP1scZFmWYKVsD9JSAOEX53lZWAF4gANuR9N_w5S7wb5-qsUcrD7Mb3AecREKAFBJ1aNHlPNoZdU0fCRSLA2dwPVl8Bf-2BQdB4Wgec0ZBUw-t40QALzSc-gLWa8oL6E4cFtHjguguK_abXuqX0he6qSszLpVyHOpF5dReJ22UgRLI5BPaGRn_1Ppen1uLWBtKvdmQ","DP":"4Ud2MTnS6rD1_mhmvvSSH_koj7DU3Eu03ornkzbtYtxKEsr1jQYot5kn3Tz82kiOfz6EqCq9avBhzWFGqacNv9rnoSZDQoBgn_hwtYQuhQnZizMIBsfu2YMvuWpSOqXsiJKMOY2voVj2MCcrKzkzO2emjnCgSgGLgnTpPNMeZZk","DQ":"j9N4UFrWXFrnN8ueV5BvCFPVR3rCkQM5VtYbVuNr4Hg_vZ7q4BfChC6cOoVzu8mdbEhUZStNjWw-qDfUU4g5UfIyy8Wd5PPaaoR71eMpY1sUeDpmwUzcXnhaiouaBjmkEdRbFqpPcEKdvM9lgI9shGPBuGigK_BnCBUTKMDa4EM","E":"AQAB","K":null,"KeyId":"22FA1AC0DC170A29CAA724FD239AEF60","Kid":"22FA1AC0DC170A29CAA724FD239AEF60","Kty":"RSA","N":"xwskHLqkzp8bt0X3P8tUKM_2laM7dKz5X3UdJm27WSziqA_2oaccYY8XMnBdZeRPlXbHMAnUmZocOAbRcUKvymtTl47OGpLlazEdcKUDDklzcC9jf_zMi2C4Fy6M_j3kh1YT0oZqUSEUHbBtHRgbP7gyIM1eUyM7-jf2GRFzvC5zZYGaqKAqXDvQ1ew9Juk_QEndRgIpiEU9_-QlIrVBrUqTdxWf3SsbsBpOZgYKsE88TNUHFCBpFmQtyoEDKtmz-k3JkruBLJlZIztOqtgnDWddUvIrzM_NZ-zjzd72JGDiTZ0EHqQL66-LXSXtf_LB4Db-Hy-FceePOckN7BlRiQ","Oth":null,"P":"4-IwXgK0CpLFiIlWb-pRu1q1k2QM4scvKAi_ri9zPoRXnxnoCfjY11cR3ptHzRCVO9fepTorjO2S5v4COW2DYs1Xd59qMxDYWHuZ02qfk3tK068W0HkXcfL7MpHNqeSPAFQKWlnn4IyyoxHTaBiGHHYK3ddgBzbp95_zC-MWvy8","Q":"35oGpIH5mCZzVuB6DxC43IisMmeaSnnSsnPlF13liLGq-smVnDcVkHLy7pyPG4xnr9M2AKqKn2wwGX8mazzAbLNfGzob3Zb_OyL2ocMJXIKdAK3raUteKtFcWtzMneQ2aMh7Ui4OlAgTrCc-l6TjzYACgMUzSdfNxL30EmmzjMc","QI":"1-5k_RJIlPsfG-thor9IHAlyj1l_aiOcE9zgpsGurna7XhqfHFFGMjoCcqZi9-zPX4ZyTbCJtwsgIy2cwjZJ3kMDc4Fxf4WmB4okZcMPTq0EkOa6D251hv6rjJW0JWNWtEwrk-87aCi4BtlBFIG3TiXWKGtUC-PsDEiGtDlQAxM","Use":null,"X":null,"X5t":null,"X5tS256":null,"X5u":null,"Y":null,"KeySize":2048,"HasPrivateKey":true,"CryptoProviderFactory":{"CryptoProviderCache":{},"CustomCryptoProvider":null,"CacheSignatureProviders":true,"SignatureProviderObjectPoolCacheSize":48}} |
@ -0,0 +1,29 @@ |
|||
{ |
|||
"AuthServer": { |
|||
"Authority": "http://dev.ccwin-in.com:10580", |
|||
//"Authority": "http://localhost:10130", |
|||
"ClientId": "basic-web", |
|||
"ClientSecret": "1q2w3e*" |
|||
}, |
|||
"App": { |
|||
"CorsOrigins": "http://localhost:9527,http://dev.ccwin-in.com:10588,http://localhost:44307" |
|||
}, |
|||
"ConnectionStrings": { |
|||
"SettleAccountService": "Server=localhost;Database=BJABP;User ID=sa;Password=aA123456!;Trusted_Connection=False;TrustServerCertificate=True", |
|||
"Default": "Server=localhost;Database=BQ_SA;User ID=sa;Password=aA123456!;Trusted_Connection=False;TrustServerCertificate=True" |
|||
}, |
|||
"ElasticSearch": { |
|||
"Url": "http://localhost:9200" |
|||
}, |
|||
"Redis": { |
|||
"Configuration": "127.0.0.1" |
|||
}, |
|||
"Logging": { |
|||
"LogLevel": { |
|||
"Default": "Warning" |
|||
} |
|||
}, |
|||
"AllowedHosts": "*", |
|||
"RePassword": "111111" |
|||
|
|||
} |
Loading…
Reference in new issue