1
我在一個新網站上使用OpenId,並試圖獲取有關用戶的一些基本信息,請參閱下面的代碼。爲什麼下面的allways是空的?DotNetOpenId - 打開Id獲取一些數據
var myData = response.GetExtension<ClaimsResponse>();
和主代碼
[System.Web.Mvc.AcceptVerbs(HttpVerbs.Get)]
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);
var myData = response.GetExtension<ClaimsResponse>();
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("Register");
}
[System.Web.Mvc.AcceptVerbs(HttpVerbs.Post)]
public ActionResult LogOn(string loginIdentifier)
{
if (!Identifier.IsValid(loginIdentifier))
{
ModelState.AddModelError("loginIdentifier",
"The specified login identifier is invalid");
return View();
}
else
{
var openid = new OpenIdRelyingParty();
IAuthenticationRequest request = openid.CreateRequest(
Identifier.Parse(loginIdentifier));
// Require some additional data
request.AddExtension(new ClaimsRequest
{
Email = DemandLevel.Request,
FullName = DemandLevel.Request
});
return request.RedirectingResponse.AsActionResult();
}
}
對於誰是有這個問題的人,看看這個 - http://dotnetopenauth.net:8000/wiki/CodeSnippets/OpenIDRP/ AXFetchAsSregTransform 我現在可以從Google收到一封電子郵件,但仍然不支持Yahoo(我不認爲他們支持AX) – LiamB 2009-10-20 10:13:26
Liam,雅虎不會給你任何用戶屬性,除非你在他們特殊的RP白名單中,少數的RP是。所以如果你收到谷歌的電子郵件,我會說你是對的。 – 2009-10-20 13:05:05
我現在設法破解它,謝謝你。這是我在下面發佈的wiki文章,幫助我取得了進展!乾杯! – LiamB 2009-10-20 13:38:07