mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Compare commits
19 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7d90ba21c2 | ||
![]() |
66110da85e | ||
![]() |
7413f4fd73 | ||
![]() |
f35c0bb865 | ||
![]() |
1df974b78c | ||
![]() |
56b369f0cb | ||
![]() |
dce31d78d9 | ||
![]() |
75253f85e2 | ||
![]() |
9cd7aad3a0 | ||
![]() |
e84a6e6521 | ||
![]() |
da210c7fcf | ||
![]() |
62f96bd1d5 | ||
![]() |
928e7e5672 | ||
![]() |
2f4d4a3c27 | ||
![]() |
898be28866 | ||
![]() |
63d11394e0 | ||
![]() |
f7192a8fce | ||
![]() |
86c01db14f | ||
![]() |
a62d36b3f8 |
10 changed files with 167 additions and 86 deletions
30
.github/workflows/jruby.yml
vendored
Normal file
30
.github/workflows/jruby.yml
vendored
Normal 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
|
24
.github/workflows/main.yml
vendored
24
.github/workflows/main.yml
vendored
|
@ -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
26
.github/workflows/truffle_ruby.yml
vendored
Normal 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
1
.gitignore
vendored
|
@ -11,3 +11,4 @@ log/*
|
|||
measurement/*
|
||||
pkg/*
|
||||
.DS_Store
|
||||
.tool-versions
|
||||
|
|
15
Gemfile
15
Gemfile
|
@ -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
147
README.md
|
@ -1,16 +1,20 @@
|
|||
# OmniAuth: Standardized Multi-Provider Authentication
|
||||
|
||||
[][gem]
|
||||
[][travis]
|
||||
[][githubactions]
|
||||
[][githubactionstruffle]
|
||||
[][githubactionsjruby]
|
||||
[][codeclimate]
|
||||
[][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.
|
||||
|
|
|
@ -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: |
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module OmniAuth
|
||||
VERSION = '2.0.4'.freeze
|
||||
VERSION = '2.1.0'.freeze
|
||||
end
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Add table
Reference in a new issue