首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在auth0中找不到连接错误

在auth0中找不到连接错误
EN

Stack Overflow用户
提问于 2017-01-19 15:29:33
回答 1查看 2.1K关注 0票数 4

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

我下载的项目是使用默认的锁屏,它的工作很好,我能够创建用户和登录,登出。

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

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

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

代码语言:javascript
复制
[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中传递了正确的连接名称,如下图所示。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-19 17:34:15

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

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

代码语言:javascript
复制
new AuthenticationRequest {
    // ...
    Connection = "Database-Connection",
    Username = vm.EmailAddress,
    Password = vm.Password
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41736126

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档