我正在使用门卫宝石
我的ApplicationController看起来像这样:
private def current_resource_owner Person.find(doorkeeper_token.resource_owner_id) if doorkeeper_token end
我的DemosController看起来像这样:
doorkeeper_for :index respond_to :json def index respond_with current_resource_owner end
回应是这样的:
Started GET "/?code=f88d2e95b1b286645d31772c395e0e36708a5i0p970836af640f631bb4f043b5" for 127.0.0.1 at 2014-01-28 11:10:56 +0530 Processing by DemosController#index as HTML Parameters: {"code"=>"f88d2e95b1b286645d31135c395e0e36708a5b5b970836af640f631bb4f043b5"} Filter chain halted as #<Proc:0xb608b90@/home/xyz/.rvm/gems/ruby-1.9.3-p484@verticalserver/gems/doorkeeper-1.0.0/lib/doorkeeper/helpers/filter.rb:8> rendered or redirected Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)
解决方法
这实际上是门卫的一个问题.要对401 Unauthorized错误而不是空白页面进行自定义JSON响应,在ApplicationController中我添加了:
def doorkeeper_unauthorized_render_options {json: '{"status": "failure","message":"401 Unauthorized"}'} end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。