我在本地运行 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
的白名单主机列表中。他们的提供者仍然没有收到任何请求。