2020-05-17 07:56:59 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Security.Claims;
|
2020-05-15 16:52:51 +01:00
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
2020-05-15 15:21:15 +01:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-05-18 08:21:34 +01:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
2020-05-17 07:56:59 +01:00
|
|
|
|
using Umbraco.Core;
|
2020-05-17 08:48:36 +01:00
|
|
|
|
using Umbraco.Core.BackOffice;
|
2020-05-15 15:21:15 +01:00
|
|
|
|
using Umbraco.Core.Mapping;
|
2020-05-17 07:56:59 +01:00
|
|
|
|
using Umbraco.Net;
|
|
|
|
|
|
using Umbraco.Web.Common.AspNetCore;
|
2020-05-15 15:21:15 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Extensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class UmbracoBackOfficeServiceCollectionExtensions
|
|
|
|
|
|
{
|
2020-05-17 10:39:30 +01:00
|
|
|
|
public static void AddUmbracoBackOfficeIdentity(this IServiceCollection services)
|
2020-05-15 15:21:15 +01:00
|
|
|
|
{
|
2020-05-18 08:21:34 +01:00
|
|
|
|
services.AddDataProtection();
|
|
|
|
|
|
|
2020-05-15 16:52:51 +01:00
|
|
|
|
// UmbracoMapper - hack?
|
2020-05-18 08:21:34 +01:00
|
|
|
|
services.TryAddSingleton<IdentityMapDefinition>();
|
|
|
|
|
|
services.TryAddSingleton(s => new MapDefinitionCollection(new[] {s.GetService<IdentityMapDefinition>()}));
|
|
|
|
|
|
services.TryAddSingleton<UmbracoMapper>();
|
2020-05-17 07:56:59 +01:00
|
|
|
|
|
2020-05-18 08:21:34 +01:00
|
|
|
|
services.TryAddScoped<IIpResolver, AspNetIpResolver>();
|
2020-05-17 07:56:59 +01:00
|
|
|
|
|
2020-05-18 08:21:34 +01:00
|
|
|
|
services.AddIdentityCore<BackOfficeIdentityUser>();
|
|
|
|
|
|
services.AddIdentityCore<BackOfficeIdentityUser>(options =>
|
2020-05-17 07:56:59 +01:00
|
|
|
|
{
|
|
|
|
|
|
options.User.RequireUniqueEmail = true;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Configure password configuration
|
|
|
|
|
|
/*options.Password.RequiredLength = passwordConfiguration.RequiredLength;
|
|
|
|
|
|
options.Password.RequireNonAlphanumeric = passwordConfiguration.RequireNonLetterOrDigit;
|
|
|
|
|
|
options.Password.RequireDigit = passwordConfiguration.RequireDigit;
|
|
|
|
|
|
options.Password.RequireLowercase = passwordConfiguration.RequireLowercase;
|
|
|
|
|
|
options.Password.RequireUppercase = passwordConfiguration.RequireUppercase;
|
|
|
|
|
|
options.Lockout.MaxFailedAccessAttempts = passwordConfiguration.MaxFailedAccessAttemptsBeforeLockout;*/
|
|
|
|
|
|
|
|
|
|
|
|
options.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier;
|
|
|
|
|
|
options.ClaimsIdentity.UserNameClaimType = ClaimTypes.Name;
|
|
|
|
|
|
options.ClaimsIdentity.RoleClaimType = ClaimTypes.Role;
|
|
|
|
|
|
options.ClaimsIdentity.SecurityStampClaimType = Constants.Web.SecurityStampClaimType;
|
|
|
|
|
|
|
|
|
|
|
|
options.Lockout.AllowedForNewUsers = true;
|
|
|
|
|
|
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromDays(30);
|
|
|
|
|
|
})
|
2020-05-15 15:21:15 +01:00
|
|
|
|
.AddDefaultTokenProviders()
|
2020-05-17 07:56:59 +01:00
|
|
|
|
.AddUserStore<BackOfficeUserStore>()
|
2020-05-18 08:21:34 +01:00
|
|
|
|
.AddUserManager<BackOfficeUserManager>()
|
|
|
|
|
|
.AddClaimsPrincipalFactory<BackOfficeClaimsPrincipalFactory<BackOfficeIdentityUser>>();
|
|
|
|
|
|
|
|
|
|
|
|
services.AddScoped<ILookupNormalizer, NopLookupNormalizer>();
|
|
|
|
|
|
services.TryAddScoped<ISecurityStampValidator, SecurityStampValidator<BackOfficeIdentityUser>>();
|
2020-05-15 15:21:15 +01:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|