2012-09-13 38 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