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

发布于 2017-01-19 17:34:15
您需要确保您传递给AuthenticateAsync的AuthenticationRequest实例中指定的Connection名称映射到您的Auth0帐户中的现有数据库连接。
更具体地说,您当前正在传递"Database-Connection"作为连接的名称,并且您需要确保具有该名称的连接存在或更改您的代码:
new AuthenticationRequest {
// ...
Connection = "Database-Connection",
Username = vm.EmailAddress,
Password = vm.Password
}https://stackoverflow.com/questions/41736126
复制相似问题