2009-09-08 12 views
6

Używam DotNetOpenAuth do integracji OpenID w naszej aplikacji internetowej. Poniższy kod wymaga podania informacji dostawcy.Dlaczego informacje o identyfikatorze openID nie są przekazywane przez protokół?

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(); 
} 

Z jakiegoś powodu odpowiedź od operatora openID nigdy nie zawiera informacji, których żądam. Poniżej znajduje się kod:

// 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"); 
    } 

Próbowałem: response.ClaimedIdentifier na milion sposobów i nigdy nie ma cennych informacji, że mogę zrobić coś z. Jakieś pomysły?

Odpowiedz

6

Właściwość IAuthenticationResponse.ClaimedIdentifier własność nigdy zawiera te atrybuty, o które prosisz. Zawiera tylko "nazwę użytkownika" użytkownika OpenID.

Wysyłasz prośbę idealnie. Po prostu dodaj trochę do obsługi pozytywnej odpowiedzi:

// 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

Cześć Andrew: Bardzo dziękuję. Google oddaje email, Yahoo nie. Doceniam twoją pomoc. – Geo

+0

Yahoo powinno być teraz ... po prostu uaktualnione, aby go wspierać. –

Powiązane problemy