Sha*_*ler 10 openid yahoo asp.net-mvc dotnetopenauth
尝试使用MyOpenID和Yahoo进行身份验证时,我收到"消息签名不正确"异常.
我几乎使用了DotNetOpenAuth 3.4.2附带的ASP.NET MVC示例代码
public ActionResult Authenticate(string openid)
{
var openIdRelyingParty = new OpenIdRelyingParty();
var authenticationResponse = openIdRelyingParty.GetResponse();
if (authenticationResponse == null)
{
// Stage 2: User submitting identifier
Identifier identifier;
if (Identifier.TryParse(openid, out identifier))
{
var realm = new Realm(Request.Url.Root() + "openid");
var authenticationRequest = openIdRelyingParty.CreateRequest(openid, realm);
authenticationRequest.RedirectToProvider();
}
else
{
return RedirectToAction("login", "home");
}
}
else
{
// Stage 3: OpenID provider sending assertion response
switch (authenticationResponse.Status)
{
case AuthenticationStatus.Authenticated:
{
// TODO
}
case AuthenticationStatus.Failed:
{
throw authenticationResponse.Exception;
}
}
}
return new EmptyResult();
}
Run Code Online (Sandbox Code Playgroud)
与Google,AOL和其他人合作正常.但是,Yahoo和MyOpenID属于AuthenticationStatus.Failed案例,但有以下异常:
DotNetOpenAuth.Messaging.Bindings.InvalidSignatureException: Message signature was incorrect.
at DotNetOpenAuth.OpenId.ChannelElements.SigningBindingElement.ProcessIncomingMessage(IProtocolMessage message) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\OpenId\ChannelElements\SigningBindingElement.cs:line 139
at DotNetOpenAuth.Messaging.Channel.ProcessIncomingMessage(IProtocolMessage message) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\Messaging\Channel.cs:line 992
at DotNetOpenAuth.OpenId.ChannelElements.OpenIdChannel.ProcessIncomingMessage(IProtocolMessage message) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\OpenId\ChannelElements\OpenIdChannel.cs:line 172
at DotNetOpenAuth.Messaging.Channel.ReadFromRequest(HttpRequestInfo httpRequest) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\Messaging\Channel.cs:line 386
at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.GetResponse(HttpRequestInfo httpRequestInfo) in c:\Users\andarno\git\dotnetopenid\src\DotNetOpenAuth\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 540
Run Code Online (Sandbox Code Playgroud)
看来其他人有同样的问题:http://trac.dotnetopenauth.net : 8000/ticket/172
有没有人有解决方法?
事实证明,这是在Web场环境中使用DotNetOpenAuth的问题.
在创建OpenIdRelyingParty时,请确保在构造函数中传递null.
这会使您的网站进入OpenID无状态或"哑"模式.用户登录时速度稍慢(如果您注意到的话)但是您必须编写IRelyingPartyApplicationStore以允许DotNetOpenAuth在您的服务器场中工作;
var openIdRelyingParty = new OpenIdRelyingParty(null);
Run Code Online (Sandbox Code Playgroud)
小智 5
所有这些讨论围绕以下问题展开:
依赖方(RP)如何确保包含身份验证令牌的请求来自他将用户请求转发给的OP(OpenId Provider)?
以下步骤说明了它的发生方式
如果LSS在消息从OP返回之前消失(某种程度上),则RP没有任何内容可以比较签名,因此无法对用户进行身份验证并抛出错误:消息签名不正确.
LSS如何消失:
这个问题的两个解决方案:
RP以哑模式运行
一个.它不在本地存储和签名,因此不使用签名比较来确保消息来自他转发给用户进行身份验证的OP
湾 相反,一旦RP从OP接收到认证消息,它就将消息发送回OP并要求他检查他是否是认证该用户并且是消息的发起者的人.如果OP回答是,我是此消息的发起人,我创建了此消息,然后用户通过RP进行身份验证
实现你自己的持久性存储,它不会消失,无论ASP.net对进程做什么,就像使用SQL存储会话状态一样.
归档时间: |
|
查看次数: |
3374 次 |
最近记录: |