# File lib/oauth/controllers/consumer_controller.rb, line 4
4: def self.included(controller)
5: controller.class_eval do
6: before_filter :login_required
7: before_filter :load_consumer, :except=>:index
8: skip_before_filter :verify_authenticity_token,:only=>:callback
9: end
10: end
# File lib/oauth/controllers/consumer_controller.rb, line 33
33: def callback
34: @request_token_secret=session[params[:oauth_token]]
35: if @request_token_secret
36: @token=@consumer.create_from_request_token(current_user,params[:oauth_token],@request_token_secret,params[:oauth_verifier])
37: if @token
38: flash[:notice] = "#{params[:id].humanize} was successfully connected to your account"
39: go_back
40: else
41: flash[:error] = "An error happened, please try connecting again"
42: redirect_to oauth_consumer_url(params[:id])
43: end
44: end
45:
46: end
# File lib/oauth/controllers/consumer_controller.rb, line 48
48: def destroy
49: throw RecordNotFound unless @token
50: @token.destroy
51: if params[:commit]=="Reconnect"
52: redirect_to oauth_consumer_url(params[:id])
53: else
54: flash[:notice] = "#{params[:id].humanize} was successfully disconnected from your account"
55:
56: go_back
57: end
58: end
# File lib/oauth/controllers/consumer_controller.rb, line 12
12: def index
13: @consumer_tokens=ConsumerToken.all :conditions=>{:user_id=>current_user.id}
14: # The services the user hasn't already connected to
15: @services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
16: end
creates request token and redirects on to oauth provider’s auth page If user is already connected it displays a page with an option to disconnect and redo
# File lib/oauth/controllers/consumer_controller.rb, line 21
21: def show
22: unless @token
23: @request_token=@consumer.get_request_token(callback_oauth_consumer_url(params[:id]))
24: session[@request_token.token]=@request_token.secret
25: if @request_token.callback_confirmed?
26: redirect_to @request_token.authorize_url
27: else
28: redirect_to(@request_token.authorize_url + "&oauth_callback=#{callback_oauth_consumer_url(params[:id])}")
29: end
30: end
31: end
Override this in your controller to decide where you want to redirect user to after callback is finished.
# File lib/oauth/controllers/consumer_controller.rb, line 63
63: def go_back
64: redirect_to root_url
65: end
# File lib/oauth/controllers/consumer_controller.rb, line 67
67: def load_consumer
68: consumer_key=params[:id].to_sym
69: throw RecordNotFound unless OAUTH_CREDENTIALS.include?(consumer_key)
70: @consumer="#{consumer_key.to_s.camelcase}Token".constantize
71: @token=@consumer.find_by_user_id current_user.id
72: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.