我在本地运行 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();
想法?我对它为什么从不提出请求感到束手无策。
EDIT: localhost
被列入白名单,如下所示:
(openid.Channel.WebRequestHandler as UntrustedWebRequestHandler).WhitelistHosts.Add("localhost");
我还尝试将其添加到白名单web.config
像这样:
<dotNetOpenAuth>
<messaging>
<untrustedWebRequest>
<whitelistHosts>
<add name="localhost"/>
</whitelistHosts>
</untrustedWebRequest>
</messaging>
</dotNetOpenAuth>
使用任一方法,localhost
出现在UntrustedWebRequestHandler
在调试器中检查时的白名单主机列表。他们的提供商仍然没有收到任何请求。