1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Compare commits

...

19 commits

Author SHA1 Message Date
Bobby McDonald
7d90ba21c2
Update SECURITY.md 2022-08-16 11:07:07 -04:00
Bobby McDonald
66110da85e
Merge pull request #1070 from HoneyryderChuck/patch-1
Added docs showing how to integrate omniauth with rack_csrf
2022-06-09 22:44:14 -04:00
Tiago
7413f4fd73
Added docs showing how to integrate omniauth with rack_csrf
Fixes #1069
2022-05-16 23:08:32 +01:00
Bobby McDonald
f35c0bb865 Fix badges 2022-04-13 15:09:38 -04:00
Bobby McDonald
1df974b78c
Merge pull request #1065 from omniauth/new-CI-workflows
Separate jruby and truffle ruby workflows
2022-04-13 15:06:26 -04:00
Bobby McDonald
56b369f0cb Update badges 2022-04-13 15:03:55 -04:00
Bobby McDonald
dce31d78d9 Separate jruby and truffle ruby workflows 2022-04-13 14:58:37 -04:00
Bobby McDonald
75253f85e2 Prep for next release cycle 2022-04-13 14:37:16 -04:00
Bobby McDonald
9cd7aad3a0 relax rack 2022-04-13 14:32:45 -04:00
Bobby McDonald
e84a6e6521 Release 2.1.0 2022-04-13 14:28:11 -04:00
Bobby McDonald
da210c7fcf
Merge pull request #1062 from barttenbrinke/feature/add_rails_section_to_readme
Update Rails integration in the README.md.
2022-04-13 14:24:36 -04:00
Bobby McDonald
62f96bd1d5
Merge pull request #1064 from omniauth/support-for-ruby-3_0
Support for ruby 3.0+
2022-04-13 14:23:58 -04:00
Bobby McDonald
928e7e5672 Support for ruby 3.0+ 2022-04-13 12:53:43 -04:00
Bart ten Brinke
2f4d4a3c27
Update README.md
Added full paths to the rails files.
2022-03-22 10:18:15 +01:00
Bart ten Brinke
898be28866
Update README.md
Added a more explicit Rails section that works with Rails 7.

Also moved some of the generic rails examples to the Rails section.
Cleaned up some code examples. Trimmed some linelengths.
2022-03-22 10:02:56 +01:00
Bobby McDonald
63d11394e0
Merge pull request #1050 from ybiquitous/add-ruby-3.0-to-ci
Add Ruby 3.0, 3.1 to CI
2022-01-25 13:17:01 -05:00
Bobby McDonald
f7192a8fce
Add 3.1 2022-01-25 13:13:50 -05:00
Masafumi Koba
86c01db14f
Add Ruby 3.0 to CI 2021-11-04 22:44:19 +09:00
Bobby McDonald
a62d36b3f8
Prepare for next dev cycle 2021-04-07 16:19:32 -04:00
10 changed files with 167 additions and 86 deletions

30
.github/workflows/jruby.yml vendored Normal file
View file

@ -0,0 +1,30 @@
name: JRuby
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos]
jruby: [jruby] # TODO: Add back jruby-head once we figure out why there's a bundler mismatch
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.jruby }}
bundler-cache: true
- name: Install dependencies
env:
JRUBY_OPTS: --debug
run: bundle install
- name: Run tests
env:
JRUBY_OPTS: --debug
run: bundle exec rake

View file

@ -20,7 +20,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu, macos]
ruby: [2.5, 2.6, 2.7, head, debug, truffleruby, truffleruby-head]
ruby: [2.5, 2.6, 2.7, '3.0', 3.1, head, debug]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
@ -32,28 +32,6 @@ jobs:
run: bundle install
- name: Run tests
run: bundle exec rake
test-jruby:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos]
jruby: [jruby] # TODO: Add back jruby-head once we figure out why there's a bundler mismatch
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.jruby }}
bundler-cache: true
- name: Install dependencies
env:
JRUBY_OPTS: --debug
run: bundle install
- name: Run tests
env:
JRUBY_OPTS: --debug
run: bundle exec rake
frozen-string-compat:
runs-on: ubuntu-18.04
steps:

26
.github/workflows/truffle_ruby.yml vendored Normal file
View file

@ -0,0 +1,26 @@
name: TruffleRuby
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos]
ruby: [truffleruby, truffleruby-head]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Install dependencies
run: bundle install
- name: Run tests
run: bundle exec rake

1
.gitignore vendored
View file

@ -11,3 +11,4 @@ log/*
measurement/*
pkg/*
.DS_Store
.tool-versions

15
Gemfile
View file

@ -1,6 +1,6 @@
source 'https://rubygems.org'
gem 'jruby-openssl', '~> 0.10.5', :platforms => :jruby
gem 'jruby-openssl', '~> 0.10.5', platforms: :jruby
gem 'rake', '>= 12.0'
gem 'yard', '>= 0.9.11'
@ -13,17 +13,16 @@ end
group :test do
gem 'coveralls_reborn', '~> 0.19.0', require: false
gem 'hashie', '>= 3.4.6', '~> 4.0.0', :platforms => [:jruby_18]
gem 'json', '~> 2.3.0', :platforms => %i[jruby_18 jruby_19 ruby_19]
gem 'mime-types', '~> 3.1', :platforms => [:jruby_18]
gem 'rack', '>= 2.0.6', :platforms => %i[jruby_18 jruby_19 ruby_19 ruby_20 ruby_21]
gem 'hashie', '>= 3.4.6', '~> 4.0.0', platforms: [:jruby_18]
gem 'json', '~> 2.3.0', platforms: %i[jruby_18 jruby_19 ruby_19]
gem 'mime-types', '~> 3.1', platforms: [:jruby_18]
gem 'rack-test'
gem 'rest-client', '~> 2.0.0', :platforms => [:jruby_18]
gem 'rest-client', '~> 2.0.0', platforms: [:jruby_18]
gem 'rspec', '~> 3.5'
gem 'rack-freeze'
gem 'rubocop', '>= 0.58.2', '< 0.69.0', :platforms => %i[ruby_20 ruby_21 ruby_22 ruby_23 ruby_24]
gem 'rubocop', '>= 0.58.2', '< 0.69.0', platforms: %i[ruby_20 ruby_21 ruby_22 ruby_23 ruby_24]
gem 'simplecov-lcov'
gem 'tins', '~> 1.13', :platforms => %i[jruby_18 jruby_19 ruby_19]
gem 'tins', '~> 1.13', platforms: %i[jruby_18 jruby_19 ruby_19]
end
gemspec

147
README.md
View file

@ -1,16 +1,20 @@
# OmniAuth: Standardized Multi-Provider Authentication
[![Gem Version](http://img.shields.io/gem/v/omniauth.svg)][gem]
[![Build Status](http://img.shields.io/travis/omniauth/omniauth.svg)][travis]
[![Ruby](https://github.com/omniauth/omniauth/actions/workflows/main.yml/badge.svg)][githubactions]
[![TruffleRuby](https://github.com/omniauth/omniauth/actions/workflows/truffle_ruby.yml/badge.svg)][githubactionstruffle]
[![JRuby](https://github.com/omniauth/omniauth/actions/workflows/jruby.yml/badge.svg)][githubactionsjruby]
[![Code Climate](https://api.codeclimate.com/v1/badges/ffd33970723587806744/maintainability)][codeclimate]
[![Coverage Status](http://img.shields.io/coveralls/omniauth/omniauth.svg)][coveralls]
[gem]: https://rubygems.org/gems/omniauth
[travis]: http://travis-ci.org/omniauth/omniauth
[githubactions]: https://github.com/omniauth/omniauth/actions/workflows/main.yml
[githubactionstruffle]: https://github.com/omniauth/omniauth/actions/workflows/truffle_ruby.yml
[githubactionsjruby]: https://github.com/omniauth/omniauth/actions/workflows/jruby.yml
[codeclimate]: https://codeclimate.com/github/omniauth/omniauth
[coveralls]: https://coveralls.io/r/omniauth/omniauth
This is the documentation for the version [v2.0.4](https://github.com/omniauth/omniauth/tree/v2.0.4) of OmniAuth.
This is the documentation for the in-development branch of OmniAuth. You can view the documentation for our latest release v2.1.0 [here](https://github.com/omniauth/omniauth/releases/tag/v2.1.0).
## An Introduction
OmniAuth is a library that standardizes multi-provider authentication for
@ -83,34 +87,7 @@ environment of a request to `/auth/:provider/callback`. This hash
contains as much information about the user as OmniAuth was able to
glean from the utilized strategy. You should set up an endpoint in your
application that matches to the callback URL and then performs whatever
steps are necessary for your application. For example, in a Rails app
you would add a line in your `routes.rb` file like this:
```ruby
post '/auth/:provider/callback', to: 'sessions#create'
```
And you might then have a `SessionsController` with code that looks
something like this:
```ruby
class SessionsController < ApplicationController
# If you're using a strategy that POSTs during callback, you'll need to skip the authenticity token check for the callback action only.
skip_before_action :verify_authenticity_token, only: :create
def create
@user = User.find_or_create_from_auth_hash(auth_hash)
self.current_user = @user
redirect_to '/'
end
protected
def auth_hash
request.env['omniauth.auth']
end
end
```
steps are necessary for your application.
The `omniauth.auth` key in the environment hash provides an
Authentication Hash which will contain information about the just
@ -124,35 +101,74 @@ environment information on the callback request. It is entirely up to
you how you want to implement the particulars of your application's
authentication flow.
**Please note:** there is currently a CSRF vulnerability which affects OmniAuth (designated [CVE-2015-9284](https://nvd.nist.gov/vuln/detail/CVE-2015-9284)) that requires mitigation at the application level. More details on how to do this can be found on the [Wiki](https://github.com/omniauth/omniauth/wiki/Resolving-CVE-2015-9284).
## rack_csrf
## Configuring The `origin` Param
The `origin` url parameter is typically used to inform where a user came from and where, should you choose to use it, they'd want to return to.
`omniauth` is not OOTB-compatible with [rack_csrf](https://github.com/baldowl/rack_csrf). In order to do so, the following code needs to be added to the application bootstrapping code:
There are three possible options:
Default Flow:
```ruby
# /auth/twitter/?origin=[URL]
# No change
# If blank, `omniauth.origin` is set to HTTP_REFERER
OmniAuth::AuthenticityTokenProtection.default_options(key: "csrf.token", authenticity_param: "_csrf")
```
Renaming Origin Param:
## Rails (without Devise)
To get started, add the following gems
**Gemfile**:
```ruby
# /auth/twitter/?return_to=[URL]
# If blank, `omniauth.origin` is set to HTTP_REFERER
provider :twitter, ENV['KEY'], ENV['SECRET'], origin_param: 'return_to'
gem 'omniauth'
gem "omniauth-rails_csrf_protection"
```
Disabling Origin Param:
Then insert OmniAuth as a middleware
**config/initializers/omniauth.rb**:
```ruby
# /auth/twitter
# Origin handled externally, if need be. `omniauth.origin` is not set
provider :twitter, ENV['KEY'], ENV['SECRET'], origin_param: false
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer if Rails.env.development?
end
```
## Integrating OmniAuth Into Your Rails API
Additional providers can be added here in the future. Next we wire it
all up using routes, a controller and a login view.
**config/routes.rb**:
```ruby
get 'auth/:provider/callback', to: 'sessions#create'
get '/login', to: 'sessions#new'
```
**app/controllers/sessions_controller.rb**:
```ruby
class SessionsController < ApplicationController
def new
render :new
end
def create
user_info = request.env['omniauth.auth']
raise user_info # Your own session management should be placed here.
end
end
```
**app/views/sessions/new.html.erb**:
```erb
<%= form_tag('/auth/developer', method: 'post', data: {turbo: false}) do %>
<button type='submit'>Login with Developer</button>
<% end %>
```
Now if you visit `/login` and click the Login button, you should see the
OmniAuth developer login screen. After submitting it, you are returned to your
application at `Sessions#create`. The raise should now display all the Omniauth
details you have available to integrate it into your own user management.
If you want out of the box usermanagement, you should consider using Omniauth
through Devise. Please visit the [Devise Github page](https://github.com/heartcombo/devise#omniauth)
for more information.
## Rails API
The following middleware are (by default) included for session management in
Rails applications. When using OmniAuth with a Rails API, you'll need to add
one of these required middleware back in:
@ -191,6 +207,33 @@ to `STDOUT` but you can configure this using `OmniAuth.config.logger`:
OmniAuth.config.logger = Rails.logger
```
## Origin Param
The `origin` url parameter is typically used to inform where a user came from
and where, should you choose to use it, they'd want to return to.
Omniauth supports the following settings which can be configured on a provider level:
**Default**:
```ruby
provider :twitter, ENV['KEY'], ENV['SECRET']
POST /auth/twitter/?origin=[URL]
# If the `origin` parameter is blank, `omniauth.origin` is set to HTTP_REFERER
```
**Using a differently named origin parameter**:
```ruby
provider :twitter, ENV['KEY'], ENV['SECRET'], origin_param: 'return_to'
POST /auth/twitter/?return_to=[URL]
# If the `return_to` parameter is blank, `omniauth.origin` is set to HTTP_REFERER
```
**Disabled**:
```ruby
provider :twitter, ENV['KEY'], ENV['SECRET'], origin_param: false
POST /auth/twitter
# This means the origin should be handled by your own application.
# Note that `omniauth.origin` will always be blank.
```
## Resources
The [OmniAuth Wiki](https://github.com/omniauth/omniauth/wiki) has
actively maintained in-depth documentation for OmniAuth. It should be
@ -201,7 +244,11 @@ OmniAuth, how it works, and how to use it.
Available as part of the Tidelift Subscription.
The maintainers of OmniAuth 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-omniauth?utm_source=undefined&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
The maintainers of OmniAuth 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-omniauth?utm_source=undefined&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
## Supported Ruby Versions
OmniAuth is tested under 2.5, 2.6, 2.7, truffleruby, and JRuby.

View file

@ -7,6 +7,7 @@ currently being supported with security updates.
| Version | Supported |
| ------- | ------------------ |
| 2.1.x | :white_check_mark: |
| 2.0.x | :white_check_mark: |
| <= 1.9.1 | :x: |

View file

@ -26,7 +26,7 @@ module OmniAuth
@options = options
end
def provider(klass, *args, &block)
def provider(klass, *args, **opts, &block)
if klass.is_a?(Class)
middleware = klass
else
@ -37,8 +37,7 @@ module OmniAuth
end
end
args.last.is_a?(Hash) ? args.push(options.merge(args.pop)) : args.push(options)
use middleware, *args, &block
use middleware, *args, **options.merge(opts), &block
end
def call(env)

View file

@ -1,3 +1,3 @@
module OmniAuth
VERSION = '2.0.4'.freeze
VERSION = '2.1.0'.freeze
end

View file

@ -6,7 +6,7 @@ require 'omniauth/version'
Gem::Specification.new do |spec|
spec.add_dependency 'hashie', ['>= 3.4.6']
spec.add_dependency 'rack', ['>= 1.6.2', '< 3']
spec.add_dependency 'rack', '>= 2.2.3'
spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_dependency 'rack-protection'
spec.add_development_dependency 'rake', '~> 12.0'