oauth-tty 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9fb5812f14a92a8a60c904bf888e20701efd84500e09b872246757702619fcd0
4
+ data.tar.gz: e8d2c97c028f5aa121dcc148665971d05d4131f9167c32d703092ffd24915308
5
+ SHA512:
6
+ metadata.gz: 4ed6e99d3681333289f5e97e05789c05392ce034e96d10beea77b8a0dbd7c7d5a31649aec74ea4c41ca08546bc8d9c7ce99a6abdf7f9274bfa7465055fbd7b53
7
+ data.tar.gz: d7fc8d67328d2b95233f5f2156e11ef24dc0c2c9fce709d40d3169ee346075e2007c9e7da9c5c2fe07a9e97f3989c77affedc136a5044c6b32347c71bbc67b7f
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+ ### Added
9
+
10
+ ### Changed
11
+
12
+ ### Fixed
13
+
14
+ ### Removed
15
+
16
+ ## [1.0.0] - 2022-08-23
17
+ ### Added
18
+ - Initial release
19
+
20
+ [Unreleased]: https://gitlab.com/oauth-xx/oauth-tty/-/compare/v1.0.0...main
21
+ [1.0.0]: https://gitlab.com/oauth-xx/oauth-tty/-/releases/tag/v1.0.0
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at peter.boling@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,23 @@
1
+ ## Contributing
2
+
3
+ Bug reports and pull requests are welcome on GitLab at [https://gitlab.com/oauth-xx/oauth-tty/][source]. This project is
4
+ intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
5
+ the [code of conduct][conduct].
6
+
7
+ To submit a patch, please fork the project and create a patch with
8
+ tests. Once you're happy with it send a pull request and post a message to the
9
+ [google group][mailinglist].
10
+
11
+ ## Contributors
12
+
13
+ [![Contributors](https://contrib.rocks/image?repo=oauth-xx/oauth-ruby)][contributors]
14
+
15
+ Made with [contributors-img][contrib-rocks].
16
+
17
+ [comment]: <> (Following links are used by README, CONTRIBUTING, Homepage)
18
+
19
+ [conduct]: https://gitlab.com/oauth-xx/oauth-tty/-/blob/main/CODE_OF_CONDUCT.md
20
+ [contributors]: https://gitlab.com/oauth-xx/oauth-tty/-/graphs/main
21
+ [mailinglist]: http://groups.google.com/group/oauth-ruby
22
+ [source]: https://gitlab.com/oauth-xx/oauth-tty/-/tree/main
23
+ [contrib-rocks]: https://contrib.rocks
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 - 2017, 2021 - 2022 Thiago Pinto & Peter Boling
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # OAuth::TTY
2
+
3
+ A TTY Command Line Interface for interacting with OAuth 1.0 services.
4
+
5
+ This library was written originally by [Thiago Pinto](https://github.com/thiagopintodev) in 2016 and bundled with the oauth gem.
6
+ It was extracted into a separate library by [Peter Boling](https://railsbling.com) in 2022 as part of the move to a stable version 1.0 for the oauth gem.
7
+
8
+ ## Installation
9
+
10
+ Install the gem and add to the application's Gemfile by executing:
11
+
12
+ $ bundle add oauth-tty
13
+
14
+ If bundler is not being used to manage dependencies, install the gem by executing:
15
+
16
+ $ gem install oauth-tty
17
+
18
+ ## Usage
19
+
20
+ For now, please see the tests.
21
+
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/oauth-xx/oauth-tty/-/issues. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://gitlab.com/oauth-xx/oauth-tty/-/blob/main/CODE_OF_CONDUCT.md).
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
35
+
36
+ ## Code of Conduct
37
+
38
+ Everyone interacting in the OAuth::TTY project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/oauth-xx/oauth-tty/-/blob/main/CODE_OF_CONDUCT.md).
data/SECURITY.md ADDED
@@ -0,0 +1,22 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ |---------|--------------------|
7
+ | 1.0.x | :white_check_mark: |
8
+
9
+ ### EOL Policy
10
+
11
+ Non-commercial support for the oldest version of Ruby (which itself is going EOL) will be dropped each year in April.
12
+
13
+ ## Reporting a Vulnerability
14
+
15
+ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
16
+ Tidelift will coordinate the fix and disclosure.
17
+
18
+ ## OAuth for Enterprise
19
+
20
+ Available as part of the Tidelift Subscription.
21
+
22
+ The maintainers of oauth-tty and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. [Learn more.](https://tidelift.com/subscription/pkg/rubygems-oauth?utm_source=rubygems-oauth&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
data/exe/oauth ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "oauth"
5
+ require "oauth_tty"
6
+
7
+ # don't dump a backtrace on a ^C
8
+ Signal.trap("INT") do
9
+ puts
10
+ exit(1)
11
+ end
12
+ ARGV << "help" if ARGV.empty?
13
+ command = ARGV.shift
14
+
15
+ OAuth::TTY::CLI.new($stdout, $stdin, $stderr, command, ARGV).run
data/lib/oauth/cli.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "oauth/tty"
4
+ require "oauth/tty/cli"
5
+
6
+ # Backwards compatibility hack.
7
+ # TODO: Remove with April 2023 release of 2.0 release of oauth gem
8
+ OAuth::CLI = OAuth::TTY::CLI
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OAuth
4
+ module TTY
5
+ class CLI
6
+ def self.puts_red(string)
7
+ puts "\033[0;91m#{string}\033[0m"
8
+ end
9
+
10
+ ALIASES = {
11
+ "h" => "help",
12
+ "v" => "version",
13
+ "q" => "query",
14
+ "a" => "authorize",
15
+ "s" => "sign"
16
+ }.freeze
17
+
18
+ def initialize(stdout, stdin, stderr, command, arguments)
19
+ klass = get_command_class(parse_command(command))
20
+ @command = klass.new(stdout, stdin, stderr, arguments)
21
+ @help_command = Commands::HelpCommand.new(stdout, stdin, stderr, [])
22
+ end
23
+
24
+ def run
25
+ @command.run
26
+ end
27
+
28
+ private
29
+
30
+ def get_command_class(command)
31
+ Object.const_get("OAuth::TTY::Commands::#{command.capitalize}Command")
32
+ end
33
+
34
+ def parse_command(command)
35
+ case command = command.to_s.downcase
36
+ when "--version", "-v"
37
+ "version"
38
+ when "--help", "-h", nil, ""
39
+ "help"
40
+ when *ALIASES.keys
41
+ ALIASES[command]
42
+ when *ALIASES.values
43
+ command
44
+ else
45
+ OAuth::TTY::CLI.puts_red "Command '#{command}' not found"
46
+ "help"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,214 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OAuth
4
+ module TTY
5
+ class Command
6
+ def initialize(stdout, stdin, stderr, arguments)
7
+ @stdout = stdout
8
+ @stdin = stdin
9
+ @stderr = stderr
10
+
11
+ @options = {}
12
+ option_parser.parse!(arguments)
13
+ end
14
+
15
+ def run
16
+ missing = required_options - options.keys
17
+ if missing.empty?
18
+ _run
19
+ else
20
+ show_missing(missing)
21
+ puts option_parser.help
22
+ end
23
+ end
24
+
25
+ def required_options
26
+ []
27
+ end
28
+
29
+ protected
30
+
31
+ attr_reader :options
32
+
33
+ def show_missing(array)
34
+ array = array.map { |s| "--#{s}" }.join(" ")
35
+ OAuth::TTY::CLI.puts_red "Options missing to OAuth CLI: #{array}"
36
+ end
37
+
38
+ def xmpp?
39
+ options[:xmpp]
40
+ end
41
+
42
+ def verbose?
43
+ options[:verbose]
44
+ end
45
+
46
+ def puts(string = nil)
47
+ @stdout.puts(string)
48
+ end
49
+
50
+ def alert(string = nil)
51
+ @stderr.puts(string)
52
+ end
53
+
54
+ def parameters
55
+ @parameters ||= begin
56
+ escaped_pairs = options[:params].collect do |pair|
57
+ if /:/.match?(pair)
58
+ Hash[*pair.split(":", 2)].collect do |k, v|
59
+ [CGI.escape(k.strip), CGI.escape(v.strip)].join("=")
60
+ end
61
+ else
62
+ pair
63
+ end
64
+ end
65
+
66
+ querystring = escaped_pairs * "&"
67
+ cli_params = CGI.parse(querystring)
68
+
69
+ {
70
+ "oauth_consumer_key" => options[:oauth_consumer_key],
71
+ "oauth_nonce" => options[:oauth_nonce],
72
+ "oauth_timestamp" => options[:oauth_timestamp],
73
+ "oauth_token" => options[:oauth_token],
74
+ "oauth_signature_method" => options[:oauth_signature_method],
75
+ "oauth_version" => options[:oauth_version]
76
+ }.reject { |_k, v| v.nil? || v == "" }.merge(cli_params)
77
+ end
78
+ end
79
+
80
+ def option_parser
81
+ @option_parser ||= OptionParser.new do |opts|
82
+ opts.banner = "Usage: oauth <command> [ARGS]"
83
+
84
+ _option_parser_defaults
85
+ _option_parser_common(opts)
86
+ _option_parser_sign_and_query(opts)
87
+ _option_parser_authorization(opts)
88
+ end
89
+ end
90
+
91
+ def _option_parser_defaults
92
+ options[:oauth_nonce] = OAuth::Helper.generate_key
93
+ options[:oauth_signature_method] = "HMAC-SHA1"
94
+ options[:oauth_timestamp] = OAuth::Helper.generate_timestamp
95
+ options[:oauth_version] = "1.0"
96
+ options[:method] = :post
97
+ options[:params] = []
98
+ options[:scheme] = :header
99
+ options[:version] = "1.0"
100
+ end
101
+
102
+ def _option_parser_common(opts)
103
+ ## Common Options
104
+
105
+ opts.on("-B", "--body", "Use the request body for OAuth parameters.") do
106
+ options[:scheme] = :body
107
+ end
108
+
109
+ opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v|
110
+ options[:oauth_consumer_key] = v
111
+ end
112
+
113
+ opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v|
114
+ options[:oauth_consumer_secret] = v
115
+ end
116
+
117
+ opts.on("-H", "--header", "Use the 'Authorization' header for OAuth parameters (default).") do
118
+ options[:scheme] = :header
119
+ end
120
+
121
+ opts.on("-Q", "--query-string", "Use the query string for OAuth parameters.") do
122
+ options[:scheme] = :query_string
123
+ end
124
+
125
+ opts.on("-O", "--options FILE", "Read options from a file") do |v|
126
+ arguments = open(v).readlines.map { |l| l.chomp.split }.flatten
127
+ options2 = parse_options(arguments)
128
+ options.merge!(options2)
129
+ end
130
+ end
131
+
132
+ def _option_parser_sign_and_query(opts)
133
+ opts.separator("\n options for signing and querying")
134
+
135
+ opts.on("--method METHOD", "Specifies the method (e.g. GET) to use when signing.") do |v|
136
+ options[:method] = v
137
+ end
138
+
139
+ opts.on("--nonce NONCE", "Specifies the nonce to use.") do |v|
140
+ options[:oauth_nonce] = v
141
+ end
142
+
143
+ opts.on("--parameters PARAMS", "Specifies the parameters to use when signing.") do |v|
144
+ options[:params] << v
145
+ end
146
+
147
+ opts.on("--signature-method METHOD", "Specifies the signature method to use; defaults to HMAC-SHA1.") do |v|
148
+ options[:oauth_signature_method] = v
149
+ end
150
+
151
+ opts.on("--token TOKEN", "Specifies the token to use.") do |v|
152
+ options[:oauth_token] = v
153
+ end
154
+
155
+ opts.on("--secret SECRET", "Specifies the token secret to use.") do |v|
156
+ options[:oauth_token_secret] = v
157
+ end
158
+
159
+ opts.on("--timestamp TIMESTAMP", "Specifies the timestamp to use.") do |v|
160
+ options[:oauth_timestamp] = v
161
+ end
162
+
163
+ opts.on("--realm REALM", "Specifies the realm to use.") do |v|
164
+ options[:realm] = v
165
+ end
166
+
167
+ opts.on("--uri URI", "Specifies the URI to use when signing.") do |v|
168
+ options[:uri] = v
169
+ end
170
+
171
+ opts.on("--version [VERSION]", "Specifies the OAuth version to use.") do |v|
172
+ options[:oauth_version] = v
173
+ end
174
+
175
+ opts.on("--no-version", "Omit oauth_version.") do
176
+ options[:oauth_version] = nil
177
+ end
178
+
179
+ opts.on("--xmpp", "Generate XMPP stanzas.") do
180
+ options[:xmpp] = true
181
+ options[:method] ||= "iq"
182
+ end
183
+
184
+ opts.on("-v", "--verbose", "Be verbose.") do
185
+ options[:verbose] = true
186
+ end
187
+ end
188
+
189
+ def _option_parser_authorization(opts)
190
+ opts.separator("\n options for authorization")
191
+
192
+ opts.on("--access-token-url URL", "Specifies the access token URL.") do |v|
193
+ options[:access_token_url] = v
194
+ end
195
+
196
+ opts.on("--authorize-url URL", "Specifies the authorization URL.") do |v|
197
+ options[:authorize_url] = v
198
+ end
199
+
200
+ opts.on("--callback-url URL", "Specifies a callback URL.") do |v|
201
+ options[:oauth_callback] = v
202
+ end
203
+
204
+ opts.on("--request-token-url URL", "Specifies the request token URL.") do |v|
205
+ options[:request_token_url] = v
206
+ end
207
+
208
+ opts.on("--scope SCOPE", "Specifies the scope (Google-specific).") do |v|
209
+ options[:scope] = v
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ # this gem is an extension of oauth gem
4
+ require "oauth/consumer"
5
+ require "oauth/errors/unauthorized"
6
+
7
+ module OAuth
8
+ module TTY
9
+ module Commands
10
+ class AuthorizeCommand < Command
11
+ def required_options
12
+ [:uri]
13
+ end
14
+
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
31
+
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
41
+
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
+ end
52
+
53
+ def ask_user_for_verifier
54
+ if options[:version] == "1.0a"
55
+ puts "Please enter the verification code provided by the SP (oauth_verifier):"
56
+ @stdin.gets.chomp
57
+ else
58
+ puts "Press return to continue..."
59
+ @stdin.gets
60
+ nil
61
+ end
62
+ end
63
+
64
+ def verbosely_get_access_token(request_token, oauth_verifier)
65
+ access_token = request_token.get_access_token(oauth_verifier: oauth_verifier)
66
+
67
+ puts "Response:"
68
+ access_token.params.each do |k, v|
69
+ puts " #{k}: #{v}" unless k.is_a?(Symbol)
70
+ end
71
+ rescue OAuth::Unauthorized => e
72
+ alert "A problem occurred while attempting to obtain an access token:"
73
+ alert e
74
+ alert e.request.body
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OAuth
4
+ module TTY
5
+ module Commands
6
+ class HelpCommand < Command
7
+ def run
8
+ puts <<-EOT
9
+ Usage: oauth COMMAND [ARGS]
10
+
11
+ Available oauth commands are:
12
+ a, authorize Obtain an access token and secret for a user
13
+ q, query Query a protected resource
14
+ s, sign Generate an OAuth signature
15
+
16
+ In addition to those, there are:
17
+ v, version Displays the current version of the library (or --version, -v)
18
+ h, help Displays this help (or --help, -h)
19
+
20
+ Tip: All commands can be run without args for specific help.
21
+
22
+
23
+ EOT
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # stdlibs
4
+ require "uri"
5
+
6
+ # this gem is an extension of oauth gem
7
+ require "oauth/helper"
8
+ require "oauth/consumer"
9
+ require "oauth/tokens/access_token"
10
+
11
+ module OAuth
12
+ module TTY
13
+ module Commands
14
+ class QueryCommand < Command
15
+ extend OAuth::Helper
16
+
17
+ def required_options
18
+ %i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret]
19
+ end
20
+
21
+ def _run
22
+ consumer = OAuth::Consumer.new(options[:oauth_consumer_key], options[:oauth_consumer_secret],
23
+ scheme: options[:scheme])
24
+
25
+ access_token = OAuth::AccessToken.new(consumer, options[:oauth_token], options[:oauth_token_secret])
26
+
27
+ # append params to the URL
28
+ uri = URI.parse(options[:uri])
29
+ params = parameters.map do |k, v|
30
+ Array(v).map do |v2|
31
+ "#{OAuth::Helper.escape(k)}=#{OAuth::Helper.escape(v2)}"
32
+ end * "&"
33
+ end
34
+ uri.query = [uri.query, *params].compact * "&"
35
+ puts uri.to_s
36
+
37
+ response = access_token.request(options[:method].to_s.downcase.to_sym, uri.to_s)
38
+ puts "#{response.code} #{response.message}"
39
+ puts response.body
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ # this gem is an extension of oauth gem
4
+ require "oauth/helper"
5
+ require "oauth/request_proxy"
6
+
7
+ module OAuth
8
+ module TTY
9
+ module Commands
10
+ class SignCommand < Command
11
+ def required_options
12
+ %i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret]
13
+ end
14
+
15
+ def _run
16
+ request = OAuth::RequestProxy.proxy \
17
+ "method" => options[:method],
18
+ "uri" => options[:uri],
19
+ "parameters" => parameters
20
+
21
+ puts_verbose_parameters(request) if verbose?
22
+
23
+ request.sign! \
24
+ consumer_secret: options[:oauth_consumer_secret],
25
+ token_secret: options[:oauth_token_secret]
26
+
27
+ if verbose?
28
+ puts_verbose_request(request)
29
+ else
30
+ puts request.oauth_signature
31
+ end
32
+ end
33
+
34
+ def puts_verbose_parameters(request)
35
+ puts "OAuth parameters:"
36
+ request.oauth_parameters.each do |k, v|
37
+ puts " #{[k, v].join(": ")}"
38
+ end
39
+ puts
40
+
41
+ if request.non_oauth_parameters.any?
42
+ puts "Parameters:"
43
+ request.non_oauth_parameters.each do |k, v|
44
+ puts " #{[k, v].join(": ")}"
45
+ end
46
+ puts
47
+ end
48
+ end
49
+
50
+ def puts_verbose_request(request)
51
+ puts "Method: #{request.method}"
52
+ puts "URI: #{request.uri}"
53
+ puts "Normalized params: #{request.normalized_parameters}" unless options[:xmpp]
54
+ puts "Signature base string: #{request.signature_base_string}"
55
+
56
+ if xmpp?
57
+ puts
58
+ puts "XMPP Stanza:"
59
+ puts xmpp_output(request)
60
+ puts
61
+ puts "Note: You may want to use bare JIDs in your URI."
62
+ puts
63
+ else
64
+ puts "OAuth Request URI: #{request.signed_uri}"
65
+ puts "Request URI: #{request.signed_uri(with_oauth: false)}"
66
+ puts "Authorization header: #{request.oauth_header(realm: options[:realm])}"
67
+ end
68
+ puts "Signature: #{request.oauth_signature}"
69
+ puts "Escaped signature: #{OAuth::Helper.escape(request.oauth_signature)}"
70
+ end
71
+
72
+ def xmpp_output(request)
73
+ <<-EOS
74
+ <oauth xmlns='urn:xmpp:oauth:0'>
75
+ <oauth_consumer_key>#{request.oauth_consumer_key}</oauth_consumer_key>
76
+ <oauth_token>#{request.oauth_token}</oauth_token>
77
+ <oauth_signature_method>#{request.oauth_signature_method}</oauth_signature_method>
78
+ <oauth_signature>#{request.oauth_signature}</oauth_signature>
79
+ <oauth_timestamp>#{request.oauth_timestamp}</oauth_timestamp>
80
+ <oauth_nonce>#{request.oauth_nonce}</oauth_nonce>
81
+ <oauth_version>#{request.oauth_version}</oauth_version>
82
+ </oauth>
83
+ EOS
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OAuth
4
+ module TTY
5
+ module Commands
6
+ class VersionCommand < Command
7
+ def run
8
+ puts <<-VERSION
9
+ OAuth Gem #{OAuth::Version::VERSION}
10
+ OAuth TTY Gem #{OAuth::TTY::Version::VERSION}
11
+ VERSION
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OAuth
4
+ module TTY
5
+ module Version
6
+ VERSION = "1.0.0"
7
+ end
8
+ end
9
+ end
data/lib/oauth/tty.rb ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # stdlib
4
+ require "optparse"
5
+
6
+ # third party gems
7
+ require "version_gem"
8
+
9
+ # For initial release as a standalone gem, this gem must not declare oauth as a dependency,
10
+ # because it *is* a dependency of oauth v1.1, and that would create a circular dependency.
11
+ # It will move to a declared dependency in a subsequent release.
12
+ require "oauth"
13
+
14
+ # this gem
15
+ require_relative "tty/version"
16
+ require_relative "tty/cli"
17
+ require_relative "tty/command"
18
+ require_relative "tty/commands/help_command"
19
+ require_relative "tty/commands/query_command"
20
+ require_relative "tty/commands/authorize_command"
21
+ require_relative "tty/commands/sign_command"
22
+ require_relative "tty/commands/version_command"
23
+
24
+ # A gem was released in 2011 which was a rudimentary commands for the oauth gem,
25
+ # thus it occupies the name in RubyGems.org.
26
+ # This library was originally written as part of the oauth gem, in 2016, as OAuth::TTY.
27
+ # This gem is named oauth-tty, but intends to have backwards compatibility with oauth gem v1.0.x.
28
+ # Now that it is being extracted there is a name conflict.
29
+ #
30
+ # oauth-cli is a backwards compatibility loader hook for bundler
31
+ # TODO: Remove with April 2023 release of 2.0 release of oauth gem
32
+ require "oauth/cli"
33
+
34
+ module OAuth
35
+ # The namespace of this gem
36
+ module TTY
37
+ end
38
+ end
39
+
40
+ OAuth::TTY::Version.class_eval do
41
+ extend VersionGem::Basic
42
+ end
data/lib/oauth_tty.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is a loader hook for bundler
4
+ require "oauth/tty"
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth-tty
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - James Pinto
8
+ - Peter Boling
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2022-08-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: version_gem
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: em-http-request
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 1.1.7
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.1.7
42
+ - !ruby/object:Gem::Dependency
43
+ name: iconv
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 5.15.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 5.15.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: mocha
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rack
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '2.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rack-test
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rake
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '13.0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '13.0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rest-client
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rubocop-lts
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '18.0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '18.0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: typhoeus
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 0.1.13
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: 0.1.13
168
+ - !ruby/object:Gem::Dependency
169
+ name: webmock
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "<="
173
+ - !ruby/object:Gem::Version
174
+ version: 3.19.0
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "<="
180
+ - !ruby/object:Gem::Version
181
+ version: 3.19.0
182
+ description: OAuth 1.0 TTY Command Line Interface
183
+ email:
184
+ - peter.boling@gmail.com
185
+ executables:
186
+ - oauth
187
+ extensions: []
188
+ extra_rdoc_files: []
189
+ files:
190
+ - CHANGELOG.md
191
+ - CODE_OF_CONDUCT.md
192
+ - CONTRIBUTING.md
193
+ - LICENSE.txt
194
+ - README.md
195
+ - SECURITY.md
196
+ - exe/oauth
197
+ - lib/oauth/cli.rb
198
+ - lib/oauth/tty.rb
199
+ - lib/oauth/tty/cli.rb
200
+ - lib/oauth/tty/command.rb
201
+ - lib/oauth/tty/commands/authorize_command.rb
202
+ - lib/oauth/tty/commands/help_command.rb
203
+ - lib/oauth/tty/commands/query_command.rb
204
+ - lib/oauth/tty/commands/sign_command.rb
205
+ - lib/oauth/tty/commands/version_command.rb
206
+ - lib/oauth/tty/version.rb
207
+ - lib/oauth_tty.rb
208
+ homepage: https://gitlab.com/pboling/oauth-commands
209
+ licenses:
210
+ - MIT
211
+ metadata:
212
+ homepage_uri: https://gitlab.com/pboling/oauth-commands
213
+ source_code_uri: https://gitlab.com/pboling/oauth-commands/-/tree/v1.0.0
214
+ changelog_uri: https://gitlab.com/pboling/oauth-commands/-/blob/v1.0.0/CHANGELOG.md
215
+ bug_tracker_uri: https://gitlab.com/pboling/oauth-commands/-/issues
216
+ documentation_uri: https://www.rubydoc.info/gems/oauth-tty/1.0.0
217
+ wiki_uri: https://gitlab.com/pboling/oauth-commands/-/wikis/home
218
+ rubygems_mfa_required: 'true'
219
+ post_install_message:
220
+ rdoc_options: []
221
+ require_paths:
222
+ - lib
223
+ required_ruby_version: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: 2.7.0
228
+ required_rubygems_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ requirements: []
234
+ rubygems_version: 3.3.20
235
+ signing_key:
236
+ specification_version: 4
237
+ summary: OAuth 1.0 TTY CLI
238
+ test_files: []