【问题标题】:The connection is not found error in auth0在 auth0 中找不到连接错误
【发布时间】:2017-06-03 19:37:30
【问题描述】:

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

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

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

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

以下是我从上述文章中粘贴的代码。

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

【问题讨论】:

    标签: asp.net-mvc authentication auth0


    【解决方案1】:

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

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

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

    【讨论】:

    • 好的,我正在传递数据库名称“Auth0AuthenticationDB”,它允许我登录,但它现在没有给我令牌信息。我在使用锁定屏幕时获得令牌
    • 工作中.. 我在登录操作时将令牌传递给 claimIdentity
    猜你喜欢
    • 2017-09-11
    • 2018-03-13
    • 2022-10-11
    • 2016-06-14
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2018-07-02
    相关资源
    最近更新 更多