Пример #1
0
        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);
        }
Пример #2
0
 public WebUserSession(IHttpContextAccessor httpContextAccessor, UserfyOptions options, ILogger <IUserSession> logger)
 {
     _httpContextAccessor = httpContextAccessor;
     _options             = options;
     _logger = logger;
 }