Class: OauthUserTokensController

Inherits:
ApplicationController
  • Object
show all
Includes:
Oauth2::Provider::TransactionHelper
Defined in:
app/controllers/oauth_user_tokens_controller.rb

Overview

Copyright © 2010 ThoughtWorks Inc. (thoughtworks.com) Licenced under the MIT License (www.opensource.org/licenses/mit-license.php)

Instance Method Summary collapse

Methods included from Oauth2::Provider::TransactionHelper

included

Instance Method Details

#indexObject



10
11
12
# File 'app/controllers/oauth_user_tokens_controller.rb', line 10

def index
  @tokens = Oauth2::Provider::OauthToken.find_all_with(:user_id, current_user_id_for_oauth)
end

#revokeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/oauth_user_tokens_controller.rb', line 14

def revoke
  token = Oauth2::Provider::OauthToken.find_by_id(params[:token_id])
  if token.nil?
    render_not_authorized
    return
  end
  if token.user_id.to_s != current_user_id_for_oauth
    render_not_authorized
    return
  end

  token.destroy
  redirect_after_revoke
end

#revoke_by_adminObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/oauth_user_tokens_controller.rb', line 29

def revoke_by_admin
  
  if params[:token_id].blank? && params[:user_id].blank?
    render_not_authorized
    return
  end
  
  if !params[:token_id].blank?
    token = Oauth2::Provider::OauthToken.find_by_id(params[:token_id])
    if token.nil?
      render_not_authorized
      return
    end
    token.destroy
  else
    Oauth2::Provider::OauthToken.find_all_with(:user_id, params[:user_id]).map(&:destroy)
  end

  redirect_after_revoke
end