2011-08-10 96 views
0

自己在使用C#中驗證交換我的應用程序implementented SSO通過Dotnetopenauth谷歌openID問題標記?

我的疑慮如下,

  1. 在我的AX請求的響應,我不接受任何令牌。我需要發送任何參數嗎?
  2. 在我的應用程序中,我需要用戶每次都登錄提供程序,但是如果用戶在「下次自動登錄」時單擊複選框,它就再也不會從用戶那裏詢問用戶名和密碼。
  3. AX fetchResponse null用於MyopenId。它是否僅支持簡單註冊?

請求代碼:

IAuthenticationRequest request = openid.CreateRequest(txt_openid_identifier.Text); 

    var fetchRequest = new FetchRequest(); 
    fetchRequest.Attributes.Clear(); 
    fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email); 
    fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.First); 
    fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.Last);      fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.HomeAddress.Country);     
      request.AddExtension(fetchRequest); 

      // Issue request to OP 
      request.RedirectToProvider(); 

響應代碼:

using (var openid = new OpenIdRelyingParty()) 
     { 
      var response = openid.GetResponse(); 

      if (response == null) return; 

      switch (response.Status) 
      { 

       case AuthenticationStatus.Authenticated: 
        string emailID = string.Empty; 
        Session["email"] = string.Empty; 
        Session["name"] = string.Empty; 
        Session["country"] = string.Empty; 
        Session["Accesskey"] = string.Empty; 
        Session["SecretAccesskey"] = string.Empty; 

        var fetchResponse = response.GetExtension<FetchResponse>(); 

        if (fetchResponse.Attributes.Contains(WellKnownAttributes.Contact.Email)) 
        { 
         IList<string> emailAddresses = 
          fetchResponse.Attributes[WellKnownAttributes.Contact.Email].Values; 
         emailID = emailAddresses.Count > 0 ? emailAddresses[0] : null; 
        } 
        else 
         emailID = string.Empty; 
      } 
     } 

回答

0

我發現,某些供應商(即myopenid.com)返回null爲FetchRequest,同時返回有效數據ClaimsRequest。看起來不同的提供者支持不同的屬性交換機制。在請求:

var request = openid.CreateRequest(Request.Form["openid_identifier"]); 

var sr = new ClaimsRequest 
{ 
    Email = DemandLevel.Request, 
    FullName = DemandLevel.Request 
}; 
request.AddExtension(sr); 

var fetchRequest = new FetchRequest(); 
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email); 
fetchRequest.Attributes.AddOptional(WellKnownAttributes.Name.FullName); 
request.AddExtension(fetchRequest); 

return request.RedirectingResponse.AsActionResult(); 

,並拿起響應時:

string email, fullName = String.Empty; 
var fetch = response.GetExtension<FetchResponse>(); 
if (fetch != null) 
{ 
    email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email); 
    fullName = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName); 
} 
var claimResponse = response.GetExtension<ClaimsResponse>(); 
if (claimResponse != null) 
{ 
    email = claimResponse.Email; 
    fullName = claimResponse.FullName; 
} 

因此,我們嘗試這兩種方式,並希望從的至少一種方法獲取數據。