简体   繁体   English

门卫撤销令牌

[英]Doorkeeper Revoke Token

I'm implementing OAuth 2 in my application, and i already have Login/Refresh Token but i'm having some troubles with logout. 我正在我的应用程序中实现OAuth 2,我已经有登录/刷新令牌,但我遇到了一些注销问题。

I have this set of routes generates by Doorkeeper: 我有这套由门卫生成的路线:

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

What i want to do is revoke a token in the server, so i think the service that i must call is "DELETE /authorize" right? 我想要做的是撤销服务器中的令牌,所以我认为我必须调用的服务是“删除/授权”吗? but i try a lot of differents ways to consume this services and i only recibe errors. 但我尝试了许多不同的方式来使用这些服务,我只重新调整错误。

By the way, i don't know if is correct to revoke the token in the server or only delete it from the application ? 顺便说一句,我不知道在服务器中撤销令牌或仅从应用程序中删除令牌是否正确?

PS: I'm using AFNetworking 2 in iOS 7 for my client. PS:我在iOS 7中使用AFNetworking 2作为我的客户端。

This does not really answer the question, but provides related information. 这并没有真正回答这个问题,而是提供相关信息。

I had the issue where doorkeeper would validate any user/password combination on a Resource Owner Password Credentials Grant request after having made any prior authorization to a valid user/password combination. 我遇到了这样的问题:在对有效用户/密码组合进行任何事先授权之后,门卫会在资源所有者密码凭证授权请求中验证任何用户/密码组合。 Scenario was: 情景是:

  • client gets authorization using valid user name and password 客户端使用有效的用户名和密码获取授权
  • client resets/forgets authorization token in order to end authorization 客户端重置/忘记授权令牌以终止授权
  • client can get a new authorization using any user name and password, authorizes for the original user. 客户端可以使用任何用户名和密码获取新授权,授权原始用户。

This turned out to be Warden keeping the authorized user in a session, and my iOS client happily maintaining the session for me. 结果是Warden将授权用户保留在会话中,我的iOS客户端很高兴为我维护会话。

I solved this by having warden immediately sign-out the user after authenticating. 我通过让warden在验证后立即注销用户来解决这个问题。 This works because, on an authorized request, OAuth gets the current user stored with the authorization token. 这是有效的,因为在授权请求中,OAuth会使用授权令牌获取当前用户。 It does not need to have the user in a session. 它不需要让用户进入会话。

The following is from config/initializers/doorkeeper.rb. 以下是config / initializers / doorkeeper.rb。 The last two lines do the sign-out after authorization. 最后两行在授权后进行注销。

# 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 

If I get you correctly the issue is 1) User goes to the client application, clicks log in 2) client applications gets authentication from the oauth-server. 如果我找到你正确的问题是1)用户进入客户端应用程序,单击登录2)客户端应用程序从oauth-server获取身份验证。 user is asked for username/password at this time 3) user clicks logout in client application 4) user clicks login again in client application, and it automatically signs him in using the old authenticated token rather than asking for username and pw again, which is what you want. 此时用户被要求输入用户名/密码3)用户点击客户端应用程序中的注销4)用户在客户端应用程序中再次单击登录,并使用旧的经过身份验证的令牌自动签入,而不是再次请求用户名和pw,这是你想要什么。

If that's your problem, it has to do with cookies. 如果这是你的问题,它与cookie有关。 Check the cookies being sent in each request. 检查每个请求中发送的cookie。 In my case, I had to add a line 在我的情况下,我不得不添加一行

cookies.delete '_oauth_server_name_session'

and it worked then. 然后它起作用了。 You can confirm it's a cookie issue first because if you switch browsers (or go into incognito mode) this won't happen. 您可以先确认这是一个cookie问题,因为如果您切换浏览器(或进入隐身模式),则不会发生这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM