DotNetOpenAuth プロジェクトの実験を始めたところです。サンプルのOpenIdRelyingPartyMvcプロジェクトを変更すると、Google と連携するClaimRequest
ためのメールを取得できました。
しかし、自分のプロジェクトに OpenID を追加しようとすると、ClaimResponse は常に null を返します。不足しているプロジェクトまたは環境設定があるかどうか疑問に思っていますか?
これが私の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();
}
}