在Auth0中出现了"连接未找到"错误

3

我正在使用auth0来维护用户详细信息,并且我正在遵循这篇文章

我下载了一个使用默认锁屏的项目,它正常运行,我能够创建用户并登录、注销。

当我尝试使用自定义登录视图并使用我的凭据登录时,它会给我一个“未找到连接”的错误。

我不确定我需要在此处传递哪个连接。

下面是我从上述文章中复制的代码。

[HttpPost]
        public async Task<ActionResult> Login(LoginViewModel vm, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    AuthenticationApiClient client =
                        new AuthenticationApiClient(
                            new Uri($"https://{ConfigurationManager.AppSettings["auth0:Domain"]}/"));

                    var result = await client.AuthenticateAsync(new AuthenticationRequest
                    {
                        ClientId = ConfigurationManager.AppSettings["auth0:ClientId"],
                        Scope = "openid",
                        Connection = "Database-Connection", // Specify the correct name of your DB connection
                        Username = vm.EmailAddress,
                        Password = vm.Password
                    });

                    // Get user info from token
                    var user = await client.GetTokenInfoAsync(result.IdToken);

                    // Create claims principal
                    var claimsIdentity = new ClaimsIdentity(new[]
                    {
                    new Claim(ClaimTypes.NameIdentifier, user.UserId),
                    new Claim(ClaimTypes.Name, user.FullName ?? user.Email),
                    new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string")
                }, DefaultAuthenticationTypes.ApplicationCookie);

                    // Sign user into cookie middleware
                    AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = false }, claimsIdentity);

                    return RedirectToLocal(returnUrl);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            }

            return View(vm);
        }

以下是我收到的错误信息:

错误详情

我在AuthenticationRequest中也传递了正确的连接名称,如下图所示:

连接名称

1个回答

2

您需要确保传入AuthenticateAsyncAuthenticationRequest实例中指定的Connection名称映射到您Auth0账户中现有的数据库连接。

更具体地说,您当前正在传递"Database-Connection"作为连接名称,您需要确保存在具有该名称的连接或更改您的代码:

new AuthenticationRequest {
    // ...
    Connection = "Database-Connection",
    Username = vm.EmailAddress,
    Password = vm.Password
}

好的,我正在传递数据库名称“Auth0AuthenticationDB”,它允许我登录,但现在它没有给我令牌信息。当我使用锁定屏幕时,我可以获取令牌。 - Keval Patel
正在工作中... 我在登录操作中通过claimsIdentity传递令牌。 - Keval Patel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接