【问题标题】:strange error dotnetopenauth when denying access to a third party app拒绝访问第三方应用程序时出现奇怪的错误 dotnetopenauth
【发布时间】:2012-02-08 02:31:17
【问题描述】:

我一直致力于开发 OAuth2 提供程序,并且我正在使用 DotNetOpenAuth,我认为我一切正常,但我忘记了如果我拒绝访问第三方应用程序会发生什么。好吧,图书馆似乎出了点问题,因为它抛出了一个我不明白的错误。

我的开发基于 dotnetopenauth ctp 示例,有一个 oauth 提供程序实现,并试图拒绝访问示例上的应用程序,同样的事情发生了。

错误是:DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationFailedResponse 消息中缺少以下必需参数:错误

堆栈跟踪:http://pastebin.com/U95NTVxe

所以:

  • 应用授权请求
  • 那我登录需要授权的用户
  • 然后身份验证服务器询问用户是否愿意授予应用访问他的资源的权限
  • 当用户点击否时,会出现此错误

谢谢你。

【问题讨论】:

    标签: c# dotnetopenauth oauth-2.0


    【解决方案1】:

    我不得不处理同样的问题。我通过将 IDirectProtocolMessage 转换为 EndUserAuthorizationFailedResponse 来修复它,然后自己设置错误并将此对象响应传递给 PrepareResponse()。

    public ActionResult AuthorizeResponse(bool isApproved)
        {
            var pendingRequest = this.authorizationServer.ReadAuthorizationRequest();
    
            IDirectedProtocolMessage response;
            if (isApproved)
            {
                //TODO Save authorization here
                response = this.authorizationServer.PrepareApproveAuthorizationRequest(pendingRequest, SessionManager.SsoUser.Username);
            }
            else
            {
                response = this.authorizationServer.PrepareRejectAuthorizationRequest(pendingRequest);
    
                // Here I set the error by myself
                var errorResponse = response as EndUserAuthorizationFailedResponse;
                errorResponse.Error = "access_denied";
                errorResponse.ErrorDescription = "User rejected the authorization.";
    
                // And return errorResponse instead of simple response
                return this.authorizationServer.Channel.PrepareResponse(errorResponse).AsActionResult();
            }
            return this.authorizationServer.Channel.PrepareResponse(response).AsActionResult();
        }
    

    希望这会有所帮助;)

    【讨论】:

    • 如何从客户端处理?我按照授权服务器端的建议做了,但是当我调用“var authorization = client.ProcessUserAuthorization();”时从客户端站点返回不包含任何有关错误消息的信息的非空对象...
    • client.ProcessUserAuthorization() 用于获取授权码(在 Token 端点上)。这意味着这个错误是在 Client.RequestUserAuthorization(scopes, returnUrl) 中处理的。在 Token 端点中,我只是用 try catch 块包围了 server.HandleTokenRequest() ,如果抛出异常,我返回 Json 序列化对象,例如 { error:"error code, 通常为 500", errorDescription="error description with exception message"}。
    【解决方案2】:

    OAuth 2 规范中的错误处理不是很稳定(规范本身尚未完成)。因此,DotNetOpenAuth OAuth 2.0 CTP 没有完全实现错误处理(或拒绝授权)。当规范最终确定时,您可以期待这个场景完成。

    【讨论】:

    • 拒绝场景有什么改进吗?我尝试在依赖方的授权服务器上设置错误消息(在调用 PrepareRejectAuthorizationRequest 之后)。有可能吗?
    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2017-03-04
    • 1970-01-01
    相关资源
    最近更新 更多