示例#1
0
        public static IApplicationBuilder UseCloudscribeIdentity(this IApplicationBuilder app)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            MultiTenantCookieAuthenticationEvents cookieEvents
                = app.ApplicationServices.GetService <MultiTenantCookieAuthenticationEvents>();



            //app.UseMultiTenantCookieAuthentication(options =>
            //{

            //    options.Notifications = cookieNotifications;
            //}
            // , AuthenticationScheme.External
            //);

            var options = app.ApplicationServices.GetRequiredService <IOptions <IdentityOptions> >().Value;

            if (options == null)
            {
                throw new ArgumentException("failed to get identity options");
            }
            if (options.Cookies.ApplicationCookie == null)
            {
                throw new ArgumentException("failed to get identity application cookie options");
            }

            options.Cookies.ExternalCookie.Events               = cookieEvents;
            options.Cookies.ExternalCookie.CookieName           = AuthenticationScheme.External;
            options.Cookies.ExternalCookie.AuthenticationScheme = AuthenticationScheme.External;

            options.Cookies.TwoFactorRememberMeCookie.Events               = cookieEvents;
            options.Cookies.TwoFactorRememberMeCookie.CookieName           = AuthenticationScheme.TwoFactorRememberMe;
            options.Cookies.TwoFactorRememberMeCookie.AuthenticationScheme = AuthenticationScheme.TwoFactorRememberMe;

            options.Cookies.TwoFactorUserIdCookie.Events               = cookieEvents;
            options.Cookies.TwoFactorUserIdCookie.CookieName           = AuthenticationScheme.TwoFactorUserId;
            options.Cookies.TwoFactorUserIdCookie.AuthenticationScheme = AuthenticationScheme.TwoFactorUserId;


            options.Cookies.ApplicationCookie.CookieName           = AuthenticationScheme.Application;
            options.Cookies.ApplicationCookie.AuthenticationScheme = AuthenticationScheme.Application;
            options.Cookies.ApplicationCookie.Events = cookieEvents;

            // these need to be resolved from site settings
            //options.Lockout.DefaultLockoutTimeSpan
            //options.Lockout.MaxFailedAccessAttempts
            //options.SecurityStampValidationInterval
            //options.SignIn.RequireConfirmedEmail
            //options.SignIn.RequireConfirmedPhoneNumber
            //options.Password.RequireDigit
            //options.Password.RequiredLength
            //options.Password.RequireLowercase
            //options.Password.RequireNonLetterOrDigit
            //options.Password.RequireUppercase
            //options.User.AllowedUserNameCharacters
            //options.User.RequireUniqueEmail

            app.UseMultiTenantCookieAuthentication(options.Cookies.ExternalCookie);


            app.UseMultiTenantCookieAuthentication(options.Cookies.TwoFactorRememberMeCookie);



            app.UseMultiTenantCookieAuthentication(options.Cookies.TwoFactorUserIdCookie);



            app.UseMultiTenantCookieAuthentication(options.Cookies.ApplicationCookie);

            return(app);
        }
示例#2
0
        public static IApplicationBuilder UseCloudscribeIdentity(this IApplicationBuilder app)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            MultiTenantCookieAuthenticationEvents cookieEvents
                = app.ApplicationServices.GetService <MultiTenantCookieAuthenticationEvents>();



            //app.UseMultiTenantCookieAuthentication(options =>
            //{

            //    options.Notifications = cookieNotifications;
            //}
            // , AuthenticationScheme.External
            //);

            var options = app.ApplicationServices.GetRequiredService <IOptions <IdentityOptions> >().Value;

            if (options == null)
            {
                throw new ArgumentException("failed to get identity options");
            }
            if (options.Cookies.ApplicationCookie == null)
            {
                throw new ArgumentException("failed to get identity application cookie options");
            }

            options.Cookies.ExternalCookie.Events               = cookieEvents;
            options.Cookies.ExternalCookie.CookieName           = AuthenticationScheme.External;
            options.Cookies.ExternalCookie.AuthenticationScheme = AuthenticationScheme.External;

            options.Cookies.TwoFactorRememberMeCookie.Events               = cookieEvents;
            options.Cookies.TwoFactorRememberMeCookie.CookieName           = AuthenticationScheme.TwoFactorRememberMe;
            options.Cookies.TwoFactorRememberMeCookie.AuthenticationScheme = AuthenticationScheme.TwoFactorRememberMe;

            options.Cookies.TwoFactorUserIdCookie.Events               = cookieEvents;
            options.Cookies.TwoFactorUserIdCookie.CookieName           = AuthenticationScheme.TwoFactorUserId;
            options.Cookies.TwoFactorUserIdCookie.AuthenticationScheme = AuthenticationScheme.TwoFactorUserId;


            options.Cookies.ApplicationCookie.CookieName           = AuthenticationScheme.Application;
            options.Cookies.ApplicationCookie.AuthenticationScheme = AuthenticationScheme.Application;
            options.Cookies.ApplicationCookie.Events = cookieEvents;

            app.UseMultiTenantCookieAuthentication(options.Cookies.ExternalCookie);


            app.UseMultiTenantCookieAuthentication(options.Cookies.TwoFactorRememberMeCookie);



            app.UseMultiTenantCookieAuthentication(options.Cookies.TwoFactorUserIdCookie);



            app.UseMultiTenantCookieAuthentication(options.Cookies.ApplicationCookie);

            return(app);
        }