我正在开发一个ASP.NET MVC应用程序,我想使用OpenId.
什么是最好的选择?
有谁知道StackOverflow使用什么?Login UI是自定义开发的,还是由API /服务提供的?
我发现OpenID有点像一个庞大的,或者比典型的注册形式更复杂,但我觉得我在这里缺少一些东西.
根据这个问题,我应该保存我的提供商给出的唯一标识符密钥.
提供商将为每个用户提供一个唯一的ID - 您需要保存.这是您将刚刚登录的用户与数据库中的记录进行匹配的方式.
在我的代码中(取自MVC部分),这个唯一的ID在LogOn()action方法的开关内给出:
public ActionResult LogOn()
{
var openid = new OpenIdRelyingParty();
IAuthenticationResponse response = openid.GetResponse();
if (response != null)
{
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
FormsAuthentication.RedirectFromLoginPage(
response.ClaimedIdentifier, false); // <-------- ID HERE! "response.ClaimedIdentifier"
break;
case AuthenticationStatus.Canceled:
ModelState.AddModelError("loginIdentifier",
"Login was cancelled at the provider");
break;
case AuthenticationStatus.Failed:
ModelState.AddModelError("loginIdentifier",
"Login failed using the provided OpenID identifier");
break;
}
}
return View();
}
[HttpPost]
public ActionResult LogOn(string loginIdentifier)
{
if (!Identifier.IsValid(loginIdentifier))
{
ModelState.AddModelError("loginIdentifier", …Run Code Online (Sandbox Code Playgroud)