Fxc*_*ead 7 ruby-on-rails oauth-2.0 doorkeeper
我正在我的应用程序中实现OAuth 2,我已经有登录/刷新令牌,但我遇到了一些注销问题.
我有这套由门卫生成的路线:
Routes for Doorkeeper::Engine:
authorization GET /authorize(.:format) doorkeeper/authorizations#new
authorization POST /authorize(.:format) doorkeeper/authorizations#create
authorization DELETE /authorize(.:format) doorkeeper/authorizations#destroy
token POST /token(.:format) doorkeeper/tokens#create
applications GET /applications(.:format) doorkeeper/applications#index
POST /applications(.:format) doorkeeper/applications#create
new_application GET /applications/new(.:format) doorkeeper/applications#new
edit_application GET /applications/:id/edit(.:format) doorkeeper/applications#edit
application GET /applications/:id(.:format) doorkeeper/applications#show
PUT /applications/:id(.:format) doorkeeper/applications#update
DELETE /applications/:id(.:format) doorkeeper/applications#destroy
authorized_applications GET /authorized_applications(.:format) doorkeeper/authorized_applications#index
authorized_application DELETE /authorized_applications/:id(.:format) doorkeeper/authorized_applications#destroy
Run Code Online (Sandbox Code Playgroud)
我想要做的是撤销服务器中的令牌,所以我认为我必须调用的服务是"删除/授权"吗?但我尝试了许多不同的方式来使用这些服务,我只重新调整错误.
顺便说一句,我不知道在服务器中撤销令牌或仅从应用程序中删除令牌是否正确?
PS:我在iOS 7中使用AFNetworking 2作为我的客户端.
这并没有真正回答问题,但提供了相关信息。
我遇到的问题是,在对有效的用户/密码组合进行任何事先授权后,门卫会根据资源所有者密码凭据授予请求验证任何用户/密码组合。场景是:
结果证明是 Warden 将授权用户保留在会话中,而我的 iOS 客户端很乐意为我维护会话。
我通过让管理员在验证后立即注销用户来解决这个问题。这是有效的,因为在获得授权请求时,OAuth 会获取与授权令牌一起存储的当前用户。它不需要让用户参与会话。
以下来自 config/initializers/doorkeeper.rb。最后两行进行授权后的注销。
# called for Resource Owner Password Credentials Grant
resource_owner_from_credentials do
request.params[:user] = {:email => request.params[:username], :password => request.params[:password]}
request.env["devise.allow_params_authentication"] = true
user = request.env["warden"].authenticate!(:scope => :user)
env['warden'].logout
user
end
Run Code Online (Sandbox Code Playgroud)