in src/Amazon.AspNetCore.Identity.Cognito/Extensions/CognitoServiceCollectionExtensions.cs [47:83]
private static IServiceCollection InjectCognitoUser<TUser>(this IServiceCollection services, Action<IdentityOptions> identityOptions = null) where TUser : CognitoUser
{
if (identityOptions != null)
{
services.Configure(identityOptions);
services.AddIdentity<CognitoUser, CognitoRole>()
.AddDefaultTokenProviders()
.AddPasswordValidator<CognitoPasswordValidator>();
}
else
{
services.AddIdentity<CognitoUser, CognitoRole>()
.AddDefaultTokenProviders()
.AddPasswordValidator<CognitoPasswordValidator>();
var passwordValidators = services.Where(s => s.ServiceType.Equals(typeof(IPasswordValidator<CognitoUser>)));
foreach (var validator in passwordValidators.ToArray())
{
if (Equals(validator.ImplementationType, typeof(PasswordValidator<CognitoUser>)))
{
services.Remove(validator);
}
}
}
// Overrides the managers/stores with Cognito specific ones.
services.AddScoped<UserManager<TUser>, CognitoUserManager<TUser>>();
services.AddScoped<SignInManager<TUser>, CognitoSignInManager<TUser>>();
services.AddScoped<IUserStore<TUser>, CognitoUserStore<TUser>>();
services.AddScoped<IRoleStore<CognitoRole>, CognitoRoleStore<CognitoRole>>();
services.AddScoped<IUserClaimStore<TUser>, CognitoUserStore<TUser>>();
services.AddScoped<IUserClaimsPrincipalFactory<TUser>, CognitoUserClaimsPrincipalFactory<TUser>>();
services.AddSingleton<CognitoKeyNormalizer, CognitoKeyNormalizer>();
services.AddSingleton<IdentityErrorDescriber, CognitoIdentityErrorDescriber>();
services.AddHttpContextAccessor();
return services;
}