64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using xIds.Providers;
|
|
using xIds.Interfaces;
|
|
using xCommons.Extensions;
|
|
using xExceptions.Constants;
|
|
using xIdentityService.Interfaces;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace xIds.Extensions
|
|
{
|
|
public static class IdentityExtensions
|
|
{
|
|
/// <summary>
|
|
/// Register IdentityManager
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
public static void AddXIdentityManager(this IServiceCollection source)
|
|
{
|
|
source.AddScoped<IXIdentityManager, XIdentityManager>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register IdentityMessage Provider
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
public static void AddXIdentityMessageProvider(
|
|
this IServiceCollection source
|
|
)
|
|
{
|
|
source.AddScoped<IXIdentityMessageProvider, XIdentityMessageProvider>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Authorization Provider ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
public static void AddXAuthorizationProvider(
|
|
this IServiceCollection source
|
|
)
|
|
{
|
|
//
|
|
// Validate Requirements ...
|
|
var roles = source.GetRegisteredService<IXRoleProvider>();
|
|
var scopes = source.GetRegisteredService<IXScopeProvider>();
|
|
var policies = source.GetRegisteredService<IXPolicyProvider>();
|
|
var cache = source.GetRegisteredService<IXAuthorizationCache>();
|
|
var resolver = source.GetRegisteredService<IXRoleHierarchyResolver>();
|
|
|
|
//
|
|
var isInvalid =
|
|
roles.IsNull() ||
|
|
cache.IsNull() ||
|
|
scopes.IsNull() ||
|
|
policies.IsNull() ||
|
|
resolver.IsNull();
|
|
if (isInvalid)
|
|
{
|
|
XException.InvalidConfiguration.Throw();
|
|
}
|
|
|
|
//
|
|
source.AddScoped<IXAuthorizationProvider, XAuthorizationProvider>();
|
|
}
|
|
}
|
|
} |