public static IServiceCollection AddUserfy <TUser>(this IServiceCollection services, Action <UserfyOptions> setupAction) where TUser : class, IUser, IEntity { var userfyOptions = new UserfyOptions(); setupAction(userfyOptions); if (userfyOptions.CookieName.IsEmpty()) { userfyOptions.CookieName = App.Name; } // .net core services setup // services.AddSession(opt => // { // opt.Cookie.SameSite = SameSiteMode.Strict; // opt.Cookie.HttpOnly = true; // opt.Cookie.Name = userfyOptions.CookieName; // }); services.AddDistributedMemoryCache(); services.AddMemoryCache(); services .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => { options.Cookie.SameSite = SameSiteMode.Strict; options.Cookie.HttpOnly = true; options.Cookie.Name = userfyOptions.CookieName; options.LoginPath = new PathString(userfyOptions.LoginPath); }); // miru services setup services.AddSingleton <IUserSession, WebUserSession>(); services.AddSingleton <ISessionStore, HttpSessionStore>(); services.AddScoped <Authorizer>(); services.AddScoped <IUserSession <TUser>, UserSession <TUser> >(); services.AddSingleton(userfyOptions); return(services); }
public WebUserSession(IHttpContextAccessor httpContextAccessor, UserfyOptions options, ILogger <IUserSession> logger) { _httpContextAccessor = httpContextAccessor; _options = options; _logger = logger; }