last ...
This commit is contained in:
+34
-14
@@ -204,7 +204,7 @@ namespace xIds.DI
|
||||
{
|
||||
//
|
||||
source.AddXApiKeyConfiguration(configuration);
|
||||
|
||||
|
||||
//
|
||||
source.AddMemoryCache();
|
||||
source.AddScoped<IXApplicationProvider, XApplicationProvider>();
|
||||
@@ -407,33 +407,53 @@ namespace xIds.DI
|
||||
)
|
||||
{
|
||||
//
|
||||
// Adding Requirements ...
|
||||
services.AddXIdentityResourceConfiguration(configuration);
|
||||
|
||||
//
|
||||
// Create Authentication Builder ...
|
||||
var authBuilder = services.AddAuthentication();
|
||||
|
||||
|
||||
//
|
||||
// For Best Support we Have to Add ApiKey Authentication First ...
|
||||
if (addApiKeyAuthentication)
|
||||
{
|
||||
//
|
||||
authBuilder
|
||||
.AddScheme<AuthenticationSchemeOptions, XApiKeyAuthenticationHandler>(
|
||||
XAuthenticationScheme.XApiKey.GetStringValue(),
|
||||
options => { });
|
||||
}
|
||||
|
||||
//
|
||||
// Add JWT Bearer ...
|
||||
// Add JwtBearer by Smart Schema ForwardDefaultSelector ...
|
||||
authBuilder.AddJwtBearer(options =>
|
||||
{
|
||||
//
|
||||
options.SaveToken = true;
|
||||
options.RequireHttpsMetadata = false;
|
||||
// options.ForwardDefault = XAuthentication.IDENTITY_SERVER_LOCAL_API;
|
||||
|
||||
//
|
||||
options.ForwardDefault = XAuthentication.IDENTITY_SERVER_LOCAL_API;
|
||||
// Selecting Authentication Schema Based On Header ...
|
||||
options.ForwardDefaultSelector = context =>
|
||||
{
|
||||
//
|
||||
// if Header Contains X-Api-Key use Scheme XApiKey ...
|
||||
var apiKeyHeader = XHeader.ApiKey
|
||||
.GetStringValue()
|
||||
.ToNormalString();
|
||||
if (context.Request.Headers.ContainsKey(apiKeyHeader))
|
||||
{
|
||||
return XAuthenticationScheme.XApiKey.GetStringValue();
|
||||
}
|
||||
|
||||
//
|
||||
// If Not, Use Local Api ...
|
||||
return XAuthentication.IDENTITY_SERVER_LOCAL_API;
|
||||
};
|
||||
})
|
||||
.AddLocalApi();
|
||||
|
||||
//
|
||||
if (addApiKeyAuthentication)
|
||||
{
|
||||
//
|
||||
authBuilder.AddScheme<AuthenticationSchemeOptions, XApiKeyAuthenticationHandler>(
|
||||
XAuthenticationScheme.XApiKey.GetStringValue(),
|
||||
options => {}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user