2012-09-13 63 views
3

我正在嘗試使用dotnetopenauth獲得SSO openid。SSO - 找不到OpenID端點

我有兩個單獨的項目,分別調試(都在本地主機,但兩個不同的端口),一個充當提供者和一個作爲依賴方。

依賴方正在localhost:1903上運行。 供應商目前正在運行localhost:3314

依託第三方代碼:

public ActionResult Authenticate() 
    { 
     UriBuilder returnToBuilder = new UriBuilder(Request.Url); 
     returnToBuilder.Path = "/OpenId/"; 
     returnToBuilder.Query = null; 
     returnToBuilder.Fragment = null; 

     Uri returnTo = returnToBuilder.Uri; 
     returnToBuilder.Path = "/"; 
     Realm realm = returnToBuilder.Uri; 
     realm = "http://localhost:3314/OpenId/"; 
     returnTo = new Uri("http://localhost:3314/OpenId/"); 
     var response = openid.GetResponse(); 

     if (response == null) { 
      if (Request.QueryString["ReturnUrl"] != null && User.Identity.IsAuthenticated) { 
      } else { 
       string strIdentifier = "testidentifier"; 
       var request = openid.CreateRequest(
        strIdentifier, 
        realm, 
        returnTo); 

       var fetchRequest = new FetchRequest(); 
       request.AddExtension(fetchRequest); 
       request.RedirectToProvider(); 
      } 
     } else { 
      switch (response.Status) { 
       case AuthenticationStatus.Canceled: 
        //stuff got cancelled for some reason 
        break; 
       case AuthenticationStatus.Failed: 
        //response.Exception.Message; 
        break; 
       case AuthenticationStatus.Authenticated: 
        //a bunch of applying roles that i don't think we care about 
        break; 
      } 
     } 

     return new EmptyResult(); 
    } 

提供商代碼:

public ActionResult Index() 
    { 
     IAuthenticationRequest iR = (IAuthenticationRequest)Request; 

     if (iR.IsReturnUrlDiscoverable(ProviderEndpoint.Provider.Channel.WebRequestHandler) != RelyingPartyDiscoveryResult.Success) { 
      iR.IsAuthenticated = false; 
      return new EmptyResult(); 
     } 

     if (iR.IsDirectedIdentity) { 
      if (User.Identity.IsAuthenticated) { 
       iR.LocalIdentifier = BuildIdentityUrl(); 
       iR.IsAuthenticated = true; 
      } else { 
       if (iR.Immediate || ImplicitAuth) { 
        iR.IsAuthenticated = false; 
       } else { 
        if (!Request.Path.EndsWith("Login", StringComparison.OrdinalIgnoreCase)) { 
         return RedirectToAction("Login", "User"); 
        } 
       } 
      } 
     } else { 
      string userOwningOpenIdUrl = ExtractUserName(iR.LocalIdentifier); 

      iR.IsAuthenticated = userOwningOpenIdUrl == User.Identity.Name; 

      if (!iR.IsAuthenticated.Value && !ImplicitAuth && !iR.Immediate) { 
       if (!Request.Path.EndsWith("Login", StringComparison.OrdinalIgnoreCase)) { 
        return RedirectToAction("Login", "User"); 
       } 
      } 
     } 

     if (iR.IsAuthenticated.Value) { 
      var fetchRequest = iR.GetExtension<FetchRequest>(); 

      if (fetchRequest != null) { 
       var fetchResponse = new FetchResponse(); 
       //roles and stuff 

       iR.AddResponseExtension(fetchResponse); 
      } 
     } 

     return new EmptyResult(); 
    } 

我得到的錯誤,當我運行依賴方的代碼,在openid.CreateRequest方法。我在我的提供程序代碼上啓用了調試,並且它永遠不會被觸發

研究錯誤,我發現了很多關於代理問題的建議,但對我來說這不應該成爲問題,因爲我只是去localhost。

也許這是相當明顯的事情,但我不知道我做錯了什麼。

在此先感謝您的幫助!編輯:僅供參考,我從DotNetOpenAuth示例中獲得此代碼。

回答

2

那麼,我最終手動通過源代碼,並有點解決了這個問題。

原來達姆彈有點正確 - 我的第一個問題是,它並希望URI作爲標識符,所以一旦我改變了我的標識符http://localhost:3314/OpenId/(即使這不是有效的,本身),我得到了那個例外。

第二個問題是我忘了將信息添加到web.config - 因此localhost未列入白名單,CreateRequest在那裏失敗。

當我解決了這兩個問題後,我的提供程序代碼被打到了很好 - 我遇到了其他錯誤,但那是我想象的一個單獨問題。

的Web.Config:

<configSections> 
    <sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth"> 
    <section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth" requirePermission="false" allowLocation="true"/> 
    <section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth" requirePermission="false" allowLocation="true"/> 
    <section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth" requirePermission="false" allowLocation="true"/> 
    <section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth" requirePermission="false" allowLocation="true"/> 
    </sectionGroup> 
</configSections> 

<dotNetOpenAuth> 
<openid> 
    <relyingParty> 
    <security requireSsl="false"> 
     <!-- Uncomment the trustedProviders tag if your relying party should only accept positive assertions from a closed set of OpenID Providers. --> 
     <!--<trustedProviders rejectAssertionsFromUntrustedProviders="true"> 
     <add endpoint="https://www.google.com/accounts/o8/ud" /> 
     </trustedProviders>--> 
    </security> 
    <behaviors> 
     <!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible 
      with OPs that use Attribute Exchange (in various formats). --> 
     <add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth"/> 
     <!--<add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.GsaIcamProfile, DotNetOpenAuth" />--> 
    </behaviors> 
    <!-- Uncomment the following to activate the sample custom store. --> 
    <!--<store type="OpenIdRelyingPartyWebForms.CustomStore, OpenIdRelyingPartyWebForms" />--> 
    </relyingParty> 
</openid> 
<messaging> 
    <untrustedWebRequest> 
    <whitelistHosts> 
     <!-- since this is a sample, and will often be used with localhost --> 
     <add name="localhost"/> 
    </whitelistHosts> 
    </untrustedWebRequest> 
</messaging> 
<!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. --> 
<reporting enabled="true"/> 
</dotNetOpenAuth> 
1

我不確定你是否有和我一樣的問題,但是......對於我來說,如果我輸入了像「bob」這樣的用戶名稱,它會提示我輸入一個openid。當我輸入一個有效的開放標識如[email protected]時,它已經超過了這個問題。看起來像完全不可能的開放式ID的異常處理需要被扣上。

0

最近我有同樣的問題,事實證明,這個問題是不是在我的應用程序,但是,OpenID的服務器端。 當調用openID服務器時,它返回500-內部服務器錯誤,我的應用程序拋出協議異常 - 在openId.CreateRequest(Identifier.Parse(openIdServer))行上找不到OpenID端點。

我聯繫了OpenID服務器的管理員,他修復了內部服務器錯誤,並且一切正常(因爲出錯)。

DotNetOpenAuth爲什麼拋出這樣一個愚蠢的例外,這是一個問題...

+0

這個例外是有道理的。理想情況下,將有一種方法來查看更詳細的信息(實際上可能有,我不是DNOA的專家)。 – Mansfield