Module: OAuth::Controllers::ProviderController

Defined in:
lib/oauth/controllers/provider_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(controller) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/oauth/controllers/provider_controller.rb', line 5

def self.included(controller)
  controller.class_eval do
    before_filter :login_required, :only => [:authorize,:revoke]
    before_filter :login_or_oauth_required, :only => [:test_request]
    before_filter :oauth_required, :only => [:invalidate,:capabilities]
    before_filter :verify_oauth_consumer_signature, :only => [:request_token]
    before_filter :verify_oauth_request_token, :only => [:access_token]
    skip_before_filter :verify_authenticity_token, :only=>[:request_token, :access_token, :invalidate, :test_request]
  end
end

Instance Method Details

#access_tokenObject



25
26
27
28
29
30
31
32
# File 'lib/oauth/controllers/provider_controller.rb', line 25

def access_token
  @token = current_token && current_token.exchange!
  if @token
    render :text => @token.to_query
  else
    render :nothing => true, :status => 401
  end
end

#authorizeObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/oauth/controllers/provider_controller.rb', line 38

def authorize
  @token = ::RequestToken.find_by_token params[:oauth_token]
  unless @token
    render :action=>"authorize_failure"
    return
  end
  
  unless @token.invalidated?    
    if request.post? 
      if user_authorizes_token?
        @token.authorize!(current_user)
        if @token.oauth10?
          @redirect_url = URI.parse(params[:oauth_callback] || @token.client_application.callback_url)
        else
          @redirect_url = URI.parse(@token.oob? ? @token.client_application.callback_url : @token.callback_url)
        end
        
        unless @redirect_url.to_s.blank?
          if @token.oauth10?
            @redirect_url.query = @redirect_url.query.blank? ?
                                  "oauth_token=#{@token.token}" :
                                  @redirect_url.query + "&oauth_token=#{@token.token}"
            redirect_to @redirect_url.to_s
          else
            @redirect_url.query = @redirect_url.query.blank? ?
                                  "oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}" :
                                  @redirect_url.query + "&oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}"
            redirect_to @redirect_url.to_s
          end
        else
          render :action => "authorize_success"
        end
      else
        @token.invalidate!
        render :action => "authorize_failure"
      end
    end
  else
    render :action => "authorize_failure"
  end
end

#capabilitiesObject

Capabilities of current_token



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/oauth/controllers/provider_controller.rb', line 96

def capabilities
  if current_token.respond_to?(:capabilities)
    @capabilities=current_token.capabilities
  else
    @capabilities={:invalidate=>url_for(:action=>:invalidate)}
  end
  
  respond_to do |format|
    format.json {render :json=>@capabilities}
    format.xml {render :xml=>@capabilities}
  end
end

#invalidateObject

Invalidate current token



90
91
92
93
# File 'lib/oauth/controllers/provider_controller.rb', line 90

def invalidate
  current_token.invalidate!
  head :status=>410
end

#request_tokenObject



16
17
18
19
20
21
22
23
# File 'lib/oauth/controllers/provider_controller.rb', line 16

def request_token
  @token = current_client_application.create_request_token
  if @token
    render :text => @token.to_query
  else
    render :nothing => true, :status => 401
  end
end

#revokeObject



80
81
82
83
84
85
86
87
# File 'lib/oauth/controllers/provider_controller.rb', line 80

def revoke
  @token = current_user.tokens.find_by_token params[:token]
  if @token
    @token.invalidate!
    flash[:notice] = "You've revoked the token for #{@token.client_application.name}"
  end
  redirect_to oauth_clients_url
end

#test_requestObject



34
35
36
# File 'lib/oauth/controllers/provider_controller.rb', line 34

def test_request
  render :text => params.collect{|k,v|"#{k}=#{v}"}.join("&")
end