2009-09-08 63 views
6

我正在使用DotNetOpenAuth將openID集成到我們的Web應用程序中。下面的代碼請求信息給提供者。爲什麼沒有關於openID用戶通過協議的信息?

try 
{ 
    var req = openid.CreateRequest(Request.Form["openid_identifier"]); 
    req.AddExtension(new DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.ClaimsRequest 
    { 
    Email = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Require, 
    FullName = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Require, 
    Nickname = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Request, 
    PostalCode = DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.DemandLevel.Request 
    }); 

    return req.RedirectingResponse.AsActionResult(); 
} 

出於某種原因,來自openID提供程序的響應不會附帶我請求的信息。下面是代碼:

// Stage 3: OpenID Provider sending assertion response 
switch (response.Status) { 
    case AuthenticationStatus.Authenticated: 
    Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay; 
    FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false); 
    if (!string.IsNullOrEmpty(returnUrl)) { 
     return Redirect(returnUrl); 
    } else { 
     return RedirectToAction("Index", "Home"); 
    } 

我曾嘗試:response.ClaimedIdentifier在一萬元的方式和它永遠不會有,我可以做的東西有價值的信息。有任何想法嗎?

回答

6

The IAuthenticationResponse.ClaimedIdentifier property never包含您請求的這些屬性。它只包含OpenID用戶的「用戶名」。

您正在完美地發送請求。只需添加一點到您的處理的積極迴應:

// Stage 3: OpenID Provider sending assertion response 
switch (response.Status) { 
    case AuthenticationStatus.Authenticated: 
    Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay; 
    FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false); 
    var sreg = response.GetExtension<ClaimsResponse>(); 
    if (sreg != null) { // the Provider MAY not provide anything 
     // and even if it does, any of these attributes MAY be missing 
     var email = sreg.Email; 
     var fullName = sreg.FullName; 
     // get the rest of the attributes, and store them off somewhere. 
    } 
    if (!string.IsNullOrEmpty(returnUrl)) { 
     return Redirect(returnUrl); 
    } else { 
     return RedirectToAction("Index", "Home"); 
    } 
    break; 
    // ... 
+0

嗨安德魯:非常感謝它的工作。谷歌給回電子郵件,雅虎沒有。我感謝您的幫助。 – Geo 2009-09-08 18:04:12

+0

雅虎應該現在......他們只是升級來支持它。 – 2010-01-15 16:45:04