4

我在本地运行 DotNetOpenAuth 示例提供程序,它似乎可以通过 Web 浏览器正确处理请求。我可以通过处理程序在调试器中进行授权。

我有一个项目可以通过 Google 和其他提供者进行身份验证,但在示例提供者中失败。示例提供者根本看不到请求,依赖方抛出异常抱怨No OpenID endpoint found.

假设我在依赖方中执行以下操作:

string providerURL = "http://localhost/openid/provider";

// Now try the openid relying party...
var openid = new OpenIdRelyingParty();
var response = openid.GetResponse();
if (response == null)
{
    Identifier id;
    if (Identifier.TryParse(providerURL, out id))
    {
        // The following line throws the exception without ever making
        // a request to the server.
        var req = openid.CreateRequest(providerURL);
        // Would redirect here...
    }
 }

我注意到UntrustedWebRequestHandler该类阻止与主机名的连接,例如,localhost但根据测试用例或手动将其添加为白名单主机,似乎没有帮助。

我已经检查了主机是否可以通过以下方式访问:

// Check to make sure the provider URL is reachable.
// These requests are handled by the provider.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(providerURL);
HttpWebResponse httpRes = (HttpWebResponse)request.GetResponse();

想法?我不知道为什么它根本不提出请求。

编辑:localhost像这样被列入白名单:

(openid.Channel.WebRequestHandler as UntrustedWebRequestHandler).WhitelistHosts.Add("localhost");

我还尝试通过将其添加到web.config这样的方式将其列入白名单:

<dotNetOpenAuth>
    <messaging>
        <untrustedWebRequest>
            <whitelistHosts>
                <add name="localhost"/>
            </whitelistHosts>
        </untrustedWebRequest>
    </messaging>
</dotNetOpenAuth>

使用任何一种方法,在调试器中检查时都会localhost显示在UntrustedWebRequestHandler的白名单主机列表中。他们的提供者仍然没有收到任何请求。

4

1 回答 1

4

看起来您已经意识到需要将localhostRP 列入白名单才能使其正常工作。但我最近意识到的另一件事是 IIS 阻止 ASP.NET Web 应用程序对其自身执行 HTTP GET。它适用于 Visual Studio Personal Web Server,但如果您的 RP 和 OP 都托管在 IIS 下localhost,那么很可能是 IIS 阻止了它。HttpWebRequest您可以通过使用IIS 托管的 RP 与控制台应用程序中的手写测试来确认或否认这一点。

如果它们都在 IIS 下并且这就是问题所在,那么您应该使用个人 Web 服务器进行开发,或者将 IIS 上的两个站点分隔在不同的应用程序池中,或者类似的东西会有所帮助。

于 2009-12-04T21:36:38.303 回答