OAuth 1.0 is an industry-standard protocol for authorization.
This is a RubyGem for implementing both OAuth 1.0 clients and servers in Ruby applications.
See the sibling oauth2
gem for OAuth 2.0 implementations in Ruby.
- OAuth 1.0 Spec
- oauth2 sibling gem for OAuth 2.0 implementations in Ruby.
New EOL Policy
Versions 1.1.x will be EOL no later than April, 2023. Versions 1.0.x will be EOL no later than April, 2023. Versions 0.6.x will be EOL no later than April, 2023. Versions 0.5.x will be EOL no later than April, 2023.
This will facilitate dropping support for old, dead, and crusty versions of Ruby.
Non-commercial support for the oldest version of Ruby (which itself is going EOL) will be dropped each year in April.
Please upgrade to version 1.1.x. The only breaking change in 1.0.x is dropping old Rubies,
while 1.1.x extracts the CLI tool to an external gem dependency (oauth-tty
).
Project | bundle add oauth | |
---|---|---|
1️⃣ | name, license, docs | |
2️⃣ | version & activity | |
3️⃣ | maintenance & linting | |
4️⃣ | testing | |
5️⃣ | coverage & security | |
6️⃣ | resources | |
7️⃣ | spread 💖 | 🌏 👼 💻 |
Install the gem and add to the application's Gemfile by executing:
$ bundle add oauth
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install oauth
Available as part of the Tidelift Subscription.
The maintainers of OAuth2 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.
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
For more see SECURITY.md.
Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.7, 3.0, and 3.1. Ruby is limited to 2.7+ in the gemspec, and this will change with major version bumps, in accordance with the SemVer spec.
The main
branch now targets 1.1.x releases, for Ruby >= 2.7.
See v1.0-maintenance
(EOL April, 2023) branch for Ruby >= 2.7.
See v0.6-maintenance
(EOL April, 2023) branch for Ruby >= 2.4.
See v0.5-maintenance
(EOL April, 2023) branch for Ruby >= 2.0.
NOTE: No further releases of versions < 1.0.x are anticipated.
Ruby Engine Compatibility Policy
This gem is tested against MRI, and to a lesser extent, against JRuby, and Truffleruby. Each of those has varying versions that target a specific version of MRI Ruby. This gem should work in the just-listed Ruby engines according to the targeted MRI compatibility in the table below. If you would like to add support for additional engines, first make sure Github Actions supports the engine, then submit a PR to the correct maintenance branch as according to the table below.
Ruby Version Compatibility Policy
If something doesn't work on one of these interpreters, it's a bug.
This library may inadvertently work (or seem to work) on other Ruby implementations, however support will only be provided for the versions listed above.
If you would like this library to support another Ruby version, you may volunteer to be a maintainer. Being a maintainer entails making sure all tests run and pass on that implementation. When something breaks on your implementation, you will be responsible for providing patches in a timely fashion. If critical issues for a particular implementation exist at the time of a major release, support for that Ruby version may be dropped.
Ruby OAuth Version | Maintenance Branch | EOL | 🚂 Compatibility | Official 💎 | Unofficial 💎 | Incidental 💎 | |
---|---|---|---|---|---|---|---|
1️⃣ | 1.1.x | main |
04/2023 | Rails 6, 7 | 2.7, 3.0, 3.1 | none | none |
2️⃣ | 1.0.x | v1.0-maintenance |
04/2023 | Rails 6, 7 | 2.7, 3.0, 3.1 | none | none |
3️⃣ | 0.6.x | v0.6-maintenance |
04/2023 | Rails 5, 6, 7 | 2.7, 3.0, 3.1 | 2.5, 2.6 | 2.4 |
4️⃣ | 0.5.x | v0.5-maintenance |
04/2023 | Rails 2, 3, 4, 5, 6, 7 | 2.7, 3.0, 3.1 | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 | 2.0 |
5️⃣ | older | ⛔ | ⛔ | ⛔ | ⛔ | ⛔ | ⛔ |
See SECURITY.md
🚂 NOTE: See notes on Rails in next section.
This is a ruby library which is intended to be used in creating Ruby Consumer and Service Provider applications. It is NOT a Rails plugin, but could easily be used for the foundation for such a Rails plugin.
This gem was originally extracted from @pelle's oauth-plugin gem. After extraction that gem was made to depend on this gem.
Unfortunately, this gem does have some Rails related bits that are optional to load. You don't need Rails! The Rails bits may be pulled out into a separate gem with the 1.x minor updates of this gem.
We need to specify the oauth_callback
url explicitly, otherwise it defaults to
"oob" (Out of Band)
callback_url = "http://127.0.0.1:3000/oauth/callback"
Create a new OAuth::Consumer
instance by passing it a configuration hash:
oauth_consumer = OAuth::Consumer.new("key", "secret", site: "https://agree2")
Start the process by requesting a token
request_token = oauth_consumer.get_request_token(oauth_callback: callback_url)
session[:token] = request_token.token
session[:token_secret] = request_token.secret
redirect_to request_token.authorize_url(oauth_callback: callback_url)
When user returns create an access_token
hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret] }
request_token = OAuth::RequestToken.from_hash(oauth_consumer, hash)
access_token = request_token.get_access_token
# For 3-legged authorization, flow oauth_verifier is passed as param in callback
# access_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier])
@photos = access_token.get("/photos.xml")
Now that you have an access token, you can use Typhoeus to interact with the OAuth provider if you choose.
require "typhoeus"
require "oauth/request_proxy/typhoeus_request"
oauth_params = { consumer: oauth_consumer, token: access_token }
hydra = Typhoeus::Hydra.new
req = Typhoeus::Request.new(uri, options) # :method needs to be specified in options
oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(request_uri: uri))
req.options[:headers]["Authorization"] = oauth_helper.header # Signs the request
hydra.queue(req)
hydra.run
@response = req.response
Everyone interacting in this project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Bug reports and pull requests are welcome on GitLab at https://gitlab.com/oauth-xx/oauth/-/issues.
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
See CONTRIBUTING.md for detailed instructions on how to help!
See [https://gitlab.com/oauth-xx/oauth/-/graphs/main][🚎contributors]
This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. Compatibility with a major and minor versions of Ruby will only be changed with a major version bump.
As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision.
For example:
spec.add_dependency "oauth", "~> 1.1"
The gem is available as open source under the terms of the MIT License . See LICENSE.txt for the Copyright Notice.
OAuth Ruby has been created and maintained by a large number of talented individuals. The current maintainer is Peter Boling (@pboling). Please support with donations at Liberapay).
Comments are welcome. Contact the OAuth Ruby mailing list (Google Group) or join the live chat at https://gitter.im/oauth-xx/oauth-ruby.
You made it to the bottom of the page, so perhaps you'll indulge me for another 20 seconds. I maintain many dozens of gems, including this one, because I want Ruby to be a great place for people to solve problems, big and small. Please consider supporting my efforts via the giant yellow link below, or one of the others at the head of this README.