Je viens de commencer à expérimenter le projet DotNetOpenAuth. Modification de l'exemple OpenIdRelyingPartyMvc projet, j'ai été en mesure d'obtenir un ClaimRequest
pour Email de travailler avec Google.Pourquoi ma demande ClaimRequest revient-elle à zéro?
Cependant, lorsque j'ai essayé d'ajouter OpenID à mon propre projet, ClaimResponse revient toujours à zéro. Je me demande s'il y a un projet ou un environnement qui me manque?
Voici ma méthode Authenticate
:
public ActionResult Authenticate(string returnUrl)
{
var response = openid.GetResponse();
if (response == null)
{
// Stage 2: user submitting Identifier
Identifier id;
if (Identifier.TryParse(Request.Form["openid_identifier"], out id))
{
try
{
IAuthenticationRequest req = openid.CreateRequest(Request.Form["openid_identifier"]);
req.AddExtension(new ClaimsRequest { Email = DemandLevel.Require });
return req.RedirectingResponse.AsActionResult();
}
catch (ProtocolException ex)
{
ViewData["Message"] = ex.Message;
return View("Login");
}
}
else
{
ViewData["Message"] = "Invalid identifier";
return View("Login");
}
}
else
{
// Stage 3: OpenID Provider sending assertion response
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
ClaimsResponse sreg = response.GetExtension<ClaimsResponse>();
if (sreg != null)
{
var email = sreg.Email;
Session["Email"] = email;
}
Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
if (!string.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
case AuthenticationStatus.Canceled:
ViewData["Message"] = "Canceled at provider";
return View("Login");
case AuthenticationStatus.Failed:
ViewData["Message"] = response.Exception.Message;
return View("Login");
}
}
return new EmptyResult();
}
}