auth0 中找不到连接错误

The connection is not found error in auth0

我正在使用 auth0 来维护用户详细信息。我正在关注 This article.

我下载了使用默认锁屏的项目,它工作正常,我可以创建用户并登录、注销。

当我尝试使用自定义登录视图并尝试使用我的凭据登录时,出现错误 "The connection is not found"。

我不确定,我需要通过哪个连接。

下面是我从提到的文章中粘贴的代码。

[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 中传递正确的连接名称,如下图所示,

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

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

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