class OAuth::TTY::Commands::AuthorizeCommand
Public Instance Methods
_run()
click to toggle source
# File lib/oauth/tty/commands/authorize_command.rb 15 def _run 16 request_token = get_request_token 17 18 if request_token.callback_confirmed? 19 puts "Server appears to support OAuth 1.0a; enabling support." 20 options[:version] = "1.0a" 21 end 22 23 puts "Please visit this url to authorize:" 24 puts request_token.authorize_url 25 26 # parameters for OAuth 1.0a 27 oauth_verifier = ask_user_for_verifier 28 29 verbosely_get_access_token(request_token, oauth_verifier) 30 end
ask_user_for_verifier()
click to toggle source
# File lib/oauth/tty/commands/authorize_command.rb 54 def ask_user_for_verifier 55 if options[:version] == "1.0a" 56 puts "Please enter the verification code provided by the SP (oauth_verifier):" 57 @stdin.gets.chomp 58 else 59 puts "Press return to continue..." 60 @stdin.gets 61 nil 62 end 63 end
get_consumer()
click to toggle source
# File lib/oauth/tty/commands/authorize_command.rb 42 def get_consumer 43 OAuth::Consumer.new( 44 options[:oauth_consumer_key], 45 options[:oauth_consumer_secret], 46 access_token_url: options[:access_token_url], 47 authorize_url: options[:authorize_url], 48 request_token_url: options[:request_token_url], 49 scheme: options[:scheme], 50 http_method: options[:method].to_s.downcase.to_sym, 51 ) 52 end
get_request_token()
click to toggle source
# File lib/oauth/tty/commands/authorize_command.rb 32 def get_request_token 33 consumer = get_consumer 34 scope_options = options[:scope] ? {"scope" => options[:scope]} : {} 35 consumer.get_request_token({oauth_callback: options[:oauth_callback]}, scope_options) 36 rescue OAuth::Unauthorized => e 37 alert("A problem occurred while attempting to authorize:") 38 alert(e) 39 alert(e.request.body) 40 end
required_options()
click to toggle source
# File lib/oauth/tty/commands/authorize_command.rb 11 def required_options 12 [:uri] 13 end
verbosely_get_access_token(request_token, oauth_verifier)
click to toggle source
# File lib/oauth/tty/commands/authorize_command.rb 65 def verbosely_get_access_token(request_token, oauth_verifier) 66 access_token = request_token.get_access_token(oauth_verifier: oauth_verifier) 67 68 puts "Response:" 69 access_token.params.each do |k, v| 70 puts " #{k}: #{v}" unless k.is_a?(Symbol) 71 end 72 rescue OAuth::Unauthorized => e 73 alert("A problem occurred while attempting to obtain an access token:") 74 alert(e) 75 alert(e.request.body) 76 end