Browse Source
Forward Identity authentication for `Bearer`.
pull/13167/head
maliming
4 years ago
No known key found for this signature in database
GPG Key ID: 96224957E51C89E
12 changed files with
67 additions and
8 deletions
-
modules/identity/src/Volo.Abp.Identity.AspNetCore/Microsoft/AspNetCore/Extensions/DependencyInjection/AbpAspNetCoreServiceCollectionExtensions.cs
-
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server.Mongo/MyProjectNameModule.cs
-
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameModule.cs
-
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host.Mongo/MyProjectNameModule.cs
-
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/MyProjectNameModule.cs
-
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc.Mongo/MyProjectNameModule.cs
-
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs
-
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameBlazorModule.cs
-
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyProjectNameHttpApiHostModule.cs
-
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs
-
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Server.Host/MyProjectNameBlazorHostModule.cs
-
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs
|
|
|
@ -0,0 +1,26 @@ |
|
|
|
using System; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
|
|
namespace Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
|
|
|
|
public static class AbpAspNetCoreServiceCollectionExtensions |
|
|
|
{ |
|
|
|
public static IServiceCollection ForwardIdentityAuthenticationForBearer(this IServiceCollection services, string targetAuthenticationScheme = "Bearer") |
|
|
|
{ |
|
|
|
services.ConfigureApplicationCookie(options => |
|
|
|
{ |
|
|
|
options.ForwardDefaultSelector = ctx => |
|
|
|
{ |
|
|
|
string authorization = ctx.Request.Headers.Authorization; |
|
|
|
if (!authorization.IsNullOrWhiteSpace() && authorization.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase)) |
|
|
|
{ |
|
|
|
return targetAuthenticationScheme; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
return services; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using Blazorise.Bootstrap5; |
|
|
|
using Blazorise.Icons.FontAwesome; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.OpenApi.Models; |
|
|
|
using MyCompanyName.MyProjectName.Data; |
|
|
|
@ -129,7 +130,7 @@ public class MyProjectNameModule : AbpModule |
|
|
|
{ |
|
|
|
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ConfigureUrls(configuration); |
|
|
|
ConfigureBundles(); |
|
|
|
ConfigureAutoMapper(context); |
|
|
|
@ -188,6 +189,8 @@ public class MyProjectNameModule : AbpModule |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.Audience = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureLocalizationServices() |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using Blazorise.Bootstrap5; |
|
|
|
using Blazorise.Icons.FontAwesome; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.OpenApi.Models; |
|
|
|
using MyCompanyName.MyProjectName.Data; |
|
|
|
@ -125,7 +126,7 @@ public class MyProjectNameModule : AbpModule |
|
|
|
{ |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
if (hostingEnvironment.IsDevelopment()) |
|
|
|
{ |
|
|
|
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>()); |
|
|
|
@ -189,6 +190,8 @@ public class MyProjectNameModule : AbpModule |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.Audience = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureLocalizationServices() |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using Microsoft.AspNetCore.Cors; |
|
|
|
using Microsoft.AspNetCore.DataProtection; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.OpenApi.Models; |
|
|
|
using MyCompanyName.MyProjectName.Data; |
|
|
|
@ -112,7 +113,7 @@ public class MyProjectNameModule : AbpModule |
|
|
|
{ |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
if (hostingEnvironment.IsDevelopment()) |
|
|
|
{ |
|
|
|
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>()); |
|
|
|
@ -172,6 +173,8 @@ public class MyProjectNameModule : AbpModule |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.Audience = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureLocalization() |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using Microsoft.AspNetCore.Cors; |
|
|
|
using Microsoft.AspNetCore.DataProtection; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.OpenApi.Models; |
|
|
|
using MyCompanyName.MyProjectName.Data; |
|
|
|
@ -114,7 +115,7 @@ public class MyProjectNameModule : AbpModule |
|
|
|
{ |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
if (hostingEnvironment.IsDevelopment()) |
|
|
|
{ |
|
|
|
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>()); |
|
|
|
@ -174,6 +175,8 @@ public class MyProjectNameModule : AbpModule |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.Audience = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureLocalization() |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.OpenApi.Models; |
|
|
|
using MyCompanyName.MyProjectName.Data; |
|
|
|
using MyCompanyName.MyProjectName.Localization; |
|
|
|
@ -118,7 +119,7 @@ public class MyProjectNameModule : AbpModule |
|
|
|
{ |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
if (hostingEnvironment.IsDevelopment()) |
|
|
|
{ |
|
|
|
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>()); |
|
|
|
@ -176,6 +177,8 @@ public class MyProjectNameModule : AbpModule |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.Audience = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureLocalization() |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.OpenApi.Models; |
|
|
|
using MyCompanyName.MyProjectName.Data; |
|
|
|
using MyCompanyName.MyProjectName.Localization; |
|
|
|
@ -119,7 +120,7 @@ public class MyProjectNameModule : AbpModule |
|
|
|
{ |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
if (hostingEnvironment.IsDevelopment()) |
|
|
|
{ |
|
|
|
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>()); |
|
|
|
@ -178,6 +179,8 @@ public class MyProjectNameModule : AbpModule |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.Audience = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureLocalization() |
|
|
|
|
|
|
|
@ -4,6 +4,7 @@ using System.Net.Http; |
|
|
|
using Blazorise.Bootstrap5; |
|
|
|
using Blazorise.Icons.FontAwesome; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
@ -138,6 +139,8 @@ public class MyProjectNameBlazorModule : AbpModule |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.Audience = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureVirtualFileSystem(IWebHostEnvironment hostingEnvironment) |
|
|
|
|
|
|
|
@ -5,6 +5,7 @@ using System.Linq; |
|
|
|
using System.Net.Http; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Cors; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
@ -129,6 +130,8 @@ public class MyProjectNameHttpApiHostModule : AbpModule |
|
|
|
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
} |
|
|
|
|
|
|
|
private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration) |
|
|
|
|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.IO; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
@ -118,6 +119,8 @@ public class MyProjectNameWebModule : AbpModule |
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); |
|
|
|
options.Audience = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureAutoMapper() |
|
|
|
|
|
|
|
@ -5,6 +5,7 @@ using System.Threading.Tasks; |
|
|
|
using Blazorise.Bootstrap5; |
|
|
|
using Blazorise.Icons.FontAwesome; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
@ -142,6 +143,8 @@ public class MyProjectNameBlazorHostModule : AbpModule |
|
|
|
options.Audience = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
|
|
|
|
if (hostingEnvironment.IsDevelopment()) |
|
|
|
{ |
|
|
|
Configure<AbpVirtualFileSystemOptions>(options => |
|
|
|
|
|
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Cors; |
|
|
|
using Microsoft.AspNetCore.DataProtection; |
|
|
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
@ -147,6 +148,8 @@ public class MyProjectNameIdentityServerModule : AbpModule |
|
|
|
options.Audience = configuration["AuthServer:ApiName"]; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.ForwardIdentityAuthenticationForBearer(); |
|
|
|
|
|
|
|
Configure<AbpDistributedCacheOptions>(options => |
|
|
|
{ |
|
|
|
options.KeyPrefix = "MyProjectName:"; |
|
|
|
|