last ...
This commit is contained in:
+88
-11
@@ -25,7 +25,9 @@ using xIdentityModels.Configurations;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xIdentityService.Constants;
|
||||
|
||||
namespace xIds.DI
|
||||
{
|
||||
@@ -147,6 +149,64 @@ namespace xIds.DI
|
||||
services.AddSingleton<XDataServiceConfiguration>(dataServiceConfiguration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Specified ApiKey Configurations Instance ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXApiKeyConfiguration(
|
||||
this IServiceCollection source,
|
||||
XApiKeyConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
if (configuration.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
source.AddSingleton(configuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract APpi KLey Configurations from app settings
|
||||
/// and Register in Services ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXApiKeyConfiguration(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
var config = configuration.GetXApiKeyConfiguration();
|
||||
if (config.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
source.AddXApiKeyConfiguration(config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Application Provider ...
|
||||
/// Managing Applications/ApiKeys/ApiKeyUsages ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXApplicationProvider(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
source.AddXApiKeyConfiguration(configuration);
|
||||
source.AddScoped<IXApplicationProvider, XApplicationProvider>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register All Requirements For XIdentityServer Usage
|
||||
/// </summary>
|
||||
@@ -336,24 +396,41 @@ namespace xIds.DI
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="addApiKeyAuthentication"></param>
|
||||
public static void AddXIdentityServerAuthentication(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration
|
||||
IConfiguration configuration,
|
||||
bool addApiKeyAuthentication = false
|
||||
)
|
||||
{
|
||||
//
|
||||
services.AddXIdentityResourceConfiguration(configuration);
|
||||
services.AddAuthentication()
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
//
|
||||
options.SaveToken = true;
|
||||
options.RequireHttpsMetadata = false;
|
||||
|
||||
//
|
||||
options.ForwardDefault = XAuthentication.IDENTITY_SERVER_LOCAL_API;
|
||||
})
|
||||
.AddLocalApi();
|
||||
//
|
||||
var authBuilder = services.AddAuthentication();
|
||||
|
||||
//
|
||||
// Add JWT Bearer ...
|
||||
authBuilder.AddJwtBearer(options =>
|
||||
{
|
||||
//
|
||||
options.SaveToken = true;
|
||||
options.RequireHttpsMetadata = false;
|
||||
|
||||
//
|
||||
options.ForwardDefault = XAuthentication.IDENTITY_SERVER_LOCAL_API;
|
||||
})
|
||||
.AddLocalApi();
|
||||
|
||||
//
|
||||
if (addApiKeyAuthentication)
|
||||
{
|
||||
//
|
||||
authBuilder.AddScheme<AuthenticationSchemeOptions, XApiKeyAuthenticationHandler>(
|
||||
XAuthenticationScheme.XApiKey.GetStringValue(),
|
||||
options => {}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user