标签: asp.net-identity

如何在 ASP.NET Core 3.1 中的 AspnetUser 中添加列?

我创建了一个具有以下属性的应用程序用户类:

 public class ApplicationUser:IdentityUser
 {
    public string RandomPassword { get; set; }
 }
Run Code Online (Sandbox Code Playgroud)

我已将启动更新为:

services.AddIdentity<ApplicationUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)

但我的迁移为空。我希望 RandomPassword 作为 AspNetUser 表的列。

c# asp.net-mvc asp.net-identity asp.net-core asp.net-core-3.1

0
推荐指数
1
解决办法
1600
查看次数

基于配置值的.NET Core验证属性

我正在寻找一种将配置(选项)中的值注入到验证属性的参数中的方法。

让我印象深刻的场景是脚手架身份用户界面。

它提供了配置有关密码长度的选项的可能性。但生成的注册页面上不尊重更改。这是因为页面上验证属性的值是硬编码的。

有人知道这是否可能吗?

c# asp.net-identity .net-core asp.net-core

0
推荐指数
1
解决办法
1647
查看次数

在 Vue 应用程序中静默更新无限循环

我有一个 Vue 应用程序,我试图在其中设置静默令牌更新。

我的 Oidc 配置如下所示:

var mgr = new Oidc.UserManager({
    authority: process.env.VUE_APP_IDENTITY_URL,
    client_id: process.env.VUE_APP_CLIENT_ID,
    redirect_uri: process.env.VUE_APP_REDIRECT_URI,
    scope: 'openid profile',
    response_type: 'id_token token',
    silent_redirect_uri: process.env.VUE_APP_SILENT_REDIRECT_URI,
    userStore: new Oidc.WebStorageStateStore({store: localStorage}),
    automaticSilentRenew: true,
    filterProtocolClaims: true,
    loadUserInfo: true,
})
Run Code Online (Sandbox Code Playgroud)

我还有一个静态的silent-renew.html 页面:

<!DOCTYPE html>
<html>
<head>
    <title>Silent Renew Token</title>
</head>
<body>
    <script src='oidc-client.min.js'></script>
    <script>        
        new Oidc.UserManager().signinSilentCallback().catch((err) => {
            console.log(err);
        });
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我加载应用程序时,静默更新只是无限循环:

http请求

我的访问令牌不会再过期一个小时,但它仍在触发事件,我无法深入了解。有谁知道还有什么可能导致这个循环?

javascript asp.net-identity vue.js identityserver4 oidc-client-js

0
推荐指数
1
解决办法
697
查看次数

ASP.NET Core 3.1 [Authorize] 属性重定向到登录,即使是登录用户

我有一个 ASP.NET Core 沙箱项目。我已经添加了IdentityDbContext。注册页面工作正常。登录/注销页面工作正常。(可以通过为SignInManager.IsSignedIn(User)用户显示的html看到)

我有一个控制器标有[Authorize]

[Authorize]
public class MyTestController : Controller
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

当我第一次尝试导航到它时 - 它工作正常(重定向到登录页面)

但成功登录后,它再次重定向回使用相同链接登录: https://localhost:44359/Identity/Account/Login?ReturnUrl=%2FMyTest

这是我的代码Startup.cs

[Authorize]
public class MyTestController : Controller
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

以前,我为登录、注销、注册添加了脚手架身份项。没有[Authorize]工作良好的控制器。

c# asp.net-identity asp.net-core asp.net-core-middleware

0
推荐指数
1
解决办法
4686
查看次数

是否可以编写一个仅在开发环境中执行的类?

在我的startup.cs类中,我检查它是否是DEV环境,并且在我的appsettings.json和appsettings.development.json文件中有很多键值对。

但是我想封装一些仅在 DEV 环境中运行的代码,并且当部署到 UAT、TEST 或 LIVE 时,不会部署代码。

如何才能实现这一目标?

   public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseMigrationsEndPoint();
           
        }
        else
        {
             app.UseHsts();
        }
Run Code Online (Sandbox Code Playgroud)

并有一个类,因为这是我的类中的一个值,用于获取子域运行的 URL(这也是我的 IDENTITY 数据库中的角色的值)

  private string SubDomain(HttpContext httpContext)
        {
            HttpRequest request = httpContext.Request;

            string url = request.Headers["Host"];
            string subDomainUrl = url.Replace("https://", "").Split('/')[0];
Run Code Online (Sandbox Code Playgroud)

//我希望能够基于 http://localhost:44312/?role=adminUsers 获取我的域 //因此,如果它在本地主机上运行并且角色是管理员用户,则这只会在本地执行,作为远程​​ URL有http://adminusers.mydomain.com

public void ConfigureServices(IServiceCollection services)
{
    services.AddTransient<InjectMyClassHere>(); //My class or interface goes here
Run Code Online (Sandbox Code Playgroud)

我希望这一点很清楚。我怎样才能实现这个目标?即让此类仅在 DEV 中执行,而不部署在 UAT、TEST 或 LIVE 环境中

c# asp.net-roles asp.net-identity

0
推荐指数
1
解决办法
1266
查看次数

PasswordSignInAsync()似乎在没有任何错误的情况下阻塞

我正在尝试使用ASP.NET Core Identity 2.0在我现有的应用程序中设置身份验证.当我使用自己的数据库模式和类时,我有自己的User类,我不得不创建自定义UserStore和自定义UserManager.

所以我在AccountController中有我的登录功能:

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
    {
        ViewData["ReturnUrl"] = returnUrl;
        if (ModelState.IsValid)
        {
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, set lockoutOnFailure: true
            var result = await _signInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, lockoutOnFailure: false);
            if (result.Succeeded)
            {
                _logger.LogInformation("User logged in.");
                return RedirectToLocal(returnUrl);
            }
            if (result.IsLockedOut)
            {
                _logger.LogWarning("User account locked out.");
                return RedirectToAction(nameof(Lockout));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Connection failed.");
                return View(model); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-identity asp.net-core asp.net-core-identity

-1
推荐指数
1
解决办法
145
查看次数