Class: OAuth::CLI
- Inherits:
-
Object
- Object
- OAuth::CLI
- Defined in:
- lib/oauth/cli.rb
Constant Summary collapse
- SUPPORTED_COMMANDS =
{ "authorize" => "Obtain an access token and secret for a user", "debug" => "Verbosely generate an OAuth signature", "sign" => "Generate an OAuth signature" }
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(stdout, stdin, stderr, arguments = []) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
20 21 22 23 24 25 26 27 |
# File 'lib/oauth/cli.rb', line 20 def initialize @options = {} # don't dump a backtrace on a ^C trap(:INT) { exit } end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
12 13 14 |
# File 'lib/oauth/cli.rb', line 12 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/oauth/cli.rb', line 13 def @options end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
14 15 16 |
# File 'lib/oauth/cli.rb', line 14 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
14 15 16 |
# File 'lib/oauth/cli.rb', line 14 def stdout @stdout end |
Class Method Details
.execute(stdout, stdin, stderr, arguments = []) ⇒ Object
16 17 18 |
# File 'lib/oauth/cli.rb', line 16 def self.execute(stdout, stdin, stderr, arguments = []) self.new.execute(stdout, stdin, stderr, arguments) end |
Instance Method Details
#execute(stdout, stdin, stderr, arguments = []) ⇒ Object
29 30 31 32 33 34 35 36 37 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/oauth/cli.rb', line 29 def execute(stdout, stdin, stderr, arguments = []) @stdout = stdout @stdin = stdin @stderr = stderr (arguments) if && valid_command? if command == "debug" @command = "sign" @options[:verbose] = true end case command # TODO move command logic elsewhere when "authorize" # Y! token authority requires realm=yahoo.com when headers are in use # TODO remove :scheme when that's been fixed # TODO determine endpoints w/ X-RDS-Simple consumer = OAuth::Consumer.new \ [:oauth_consumer_key], [:oauth_consumer_secret], :access_token_url => [:access_token_url], :authorize_url => [:authorize_url], :request_token_url => [:request_token_url], :scheme => :query_string # get a request token request_token = consumer.get_request_token stdout.puts "Please visit this url to authorize:" stdout.puts request_token. stdout.puts "Press return to continue..." stdin.gets begin # get an access token access_token = request_token.get_access_token stdout.puts "Response:" access_token.params.each do |k,v| stdout.puts " #{k}: #{v}" end rescue OAuth::Unauthorized => e stderr.puts "A problem occurred while attempting to obtain an access token:" stderr.puts e end when "sign" parameters = prepare_parameters request = OAuth::RequestProxy.proxy \ "method" => [:method], "uri" => [:uri], "parameters" => parameters if verbose? stdout.puts "OAuth parameters:" request.oauth_parameters.each do |k,v| stdout.puts " " + [k, v] * ": " end stdout.puts if request.non_oauth_parameters.any? stdout.puts "Parameters:" request.non_oauth_parameters.each do |k,v| stdout.puts " " + [k, v] * ": " end stdout.puts end end request.sign! \ :consumer_secret => [:oauth_consumer_secret], :token_secret => [:oauth_token_secret] if verbose? stdout.puts "Method: #{request.method}" stdout.puts "URI: #{request.uri}" stdout.puts "Normalized params: #{request.normalized_parameters}" unless [:xmpp] stdout.puts "Signature base string: #{request.signature_base_string}" if [:xmpp] stdout.puts stdout.puts "XMPP Stanza:" stdout.puts <<-EOS <oauth xmlns='urn:xmpp:oauth:0'> <oauth_consumer_key>#{request.oauth_consumer_key}</oauth_consumer_key> <oauth_token>#{request.oauth_token}</oauth_token> <oauth_signature_method>#{request.oauth_signature_method}</oauth_signature_method> <oauth_signature>#{request.oauth_signature}</oauth_signature> <oauth_timestamp>#{request.}</oauth_timestamp> <oauth_nonce>#{request.oauth_nonce}</oauth_nonce> <oauth_version>#{request.oauth_version}</oauth_version> </oauth> EOS stdout.puts stdout.puts "Note: You may want to use bare JIDs in your URI." stdout.puts else stdout.puts "OAuth Request URI: #{request.signed_uri}" stdout.puts "Request URI: #{request.signed_uri(false)}" stdout.puts "Authorization header: #{request.oauth_header(:realm => [:realm])}" end stdout.puts "Signature: #{request.oauth_signature}" stdout.puts "Escaped signature: #{OAuth::Helper.escape(request.oauth_signature)}" else stdout.puts request.oauth_signature end end else usage end end |