Blazor 服务器应用程序 - 使用 CookieAuthenticationDefault 手动身份验证登录?

时间:2021-05-09 14:00:00

标签: c# asp.net asp.net-core blazor blazor-server-side

在 ASP.NET Core 中,我使用了这样的身份验证:

启动:

 services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        }).AddCookie(options =>
        {
            options.LoginPath = "/Account/Login";
            options.LogoutPath = "/Account/LogOut";
            options.ExpireTimeSpan = TimeSpan.FromMinutes(43200); // 1 month
        });

控制器:

 var claims = new List<Claim>()
                    {
                        new Claim(ClaimTypes.NameIdentifier,user.UserId.ToString()),
                        new Claim(ClaimTypes.Name,user.Mobile.ToString()),
                    };
                    var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    var principal = new ClaimsPrincipal(identity);
                    var properties = new AuthenticationProperties
                    {
                        IsPersistent = true

                    };

  

我可以在 blazor 中使用这个方法吗?

我该怎么做?

0 个答案:

没有答案
相关问题