Module: OAuth::Controllers::ProviderController
- Defined in:
- lib/oauth/controllers/provider_controller.rb
Class Method Summary collapse
Instance Method Summary collapse
- #access_token ⇒ Object
- #authorize ⇒ Object
-
#capabilities ⇒ Object
Capabilities of current_token.
-
#invalidate ⇒ Object
Invalidate current token.
- #request_token ⇒ Object
- #revoke ⇒ Object
- #test_request ⇒ Object
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_token ⇒ Object
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 |
#authorize ⇒ Object
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 |
# File 'lib/oauth/controllers/provider_controller.rb', line 38 def @token = ::RequestToken.find_by_token params[:oauth_token] unless @token render :action=>"authorize_failure" return end unless @token.invalidated? if request.post? if @token.(current_user) if @token.oauth10? @redirect_url = params[:oauth_callback] || @token.client_application.callback_url else @redirect_url = @token.oob? ? @token.client_application.callback_url : @token.callback_url end if @redirect_url if @token.oauth10? redirect_to "#{@redirect_url}?oauth_token=#{@token.token}" else redirect_to "#{@redirect_url}?oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}" end else render :action => "authorize_success" end else @token.invalidate! render :action => "authorize_failure" end end else render :action => "authorize_failure" end end |
#capabilities ⇒ Object
Capabilities of current_token
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/oauth/controllers/provider_controller.rb', line 90 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 |
#invalidate ⇒ Object
Invalidate current token
84 85 86 87 |
# File 'lib/oauth/controllers/provider_controller.rb', line 84 def invalidate current_token.invalidate! head :status=>410 end |
#request_token ⇒ Object
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 |
#revoke ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/oauth/controllers/provider_controller.rb', line 74 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_request ⇒ Object
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 |