omniauth-multi-provider 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16ff3ef4f047ef105e33b3e2442420c39eb867ea
4
- data.tar.gz: c5572a21ca416dc901a6c2d4e8ba3a3a09174ee3
3
+ metadata.gz: 8b5608e7d4138222375e7ea620ceca08cc3b0c5a
4
+ data.tar.gz: acf1a2eaef1eacf658e82f85eae08beb0b4ee076
5
5
  SHA512:
6
- metadata.gz: 2c153418eb8f3c8f6a356a3905f159afd2715b362c3d07160a23d8bc97aa0c376566f7a78bdd7fffc65d5bb5ea2c421d17bde8b9788162d98f6088256e4ab497
7
- data.tar.gz: 43de8c2fbfe2dfacf2aa67b95d9a674dc99cbfc8dea9e8c9315219b83f2ac78714dafb5e9e5434a4e35932a0b346ad37abb462e3d5c1126dbdbbdd519b06c15a
6
+ metadata.gz: 9aaa1e2239cd6ce60a4861abcd6d36b53f8c66fa5ea2d851c9fbe982203e79c436c75601ca2ee3951e52596620155cd1978a2777e5fcd52bcf22b81b9c1d66cc
7
+ data.tar.gz: 9d43e25787e436a884a637fdc23ead62b86c03268267cdcc15bee7938b5ede6436942c743ce687a3057f619d7d45aa4709a3722d2919dc8a26eb49f47b0044a5
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ omniauth-multi-provider
@@ -0,0 +1 @@
1
+ ruby-2.3.3
@@ -1,7 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.1
4
- before_install: gem install bundler -v 1.12.4
3
+ - 2.4.0
4
+ - 2.3.3
5
+ before_install:
6
+ # Workaround for https://github.com/sickill/rainbow/issues/48
7
+ - gem update --system
8
+ - gem install bundler -v 1.13.7
5
9
  script:
6
10
  - bundle exec rubocop
7
11
  - bundle exec rspec
@@ -1,4 +1,7 @@
1
1
  # omniauth-multi-provider
2
2
 
3
+ ## v0.2.0
4
+ - Support configuration of the callback suffix. Thanks [Martin Holman](https://github.com/martin308).
5
+
3
6
  ## v0.1.0
4
7
  - Initial version
data/README.md CHANGED
@@ -1,11 +1,9 @@
1
- # OmniAuth::MultiProvider
1
+ # OmniAuth MultiProvider
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be
4
- able to package up your Ruby library into a gem. Put your Ruby code in the file
5
- `lib/omniauth-multi-provider`. To experiment with that code, run
6
- `bin/console` for an interactive prompt.
7
-
8
- TODO: Delete this and the text above, and describe your gem
3
+ This is a simple extension to [omniauth](https://github.com/omniauth/omniauth) for supporting
4
+ multiple identity provider instances of a given type e.g. multiple SAML or OAuth2
5
+ identity providers. It is a generalization of the
6
+ [omniauth-multi-provider-saml](https://github.com/salsify/omniauth-multi-provider-saml).
9
7
 
10
8
  ## Installation
11
9
 
@@ -23,9 +21,71 @@ Or install it yourself as:
23
21
 
24
22
  $ gem install omniauth-multi-provider
25
23
 
26
- ## Usage
24
+ ## Setup
25
+
26
+ **Getting your setup to work with a single identity provider before attempting to use this gem is highly recommended.**
27
+
28
+ The setup process consists of the following steps:
29
+
30
+ 1. Create an OmniAuth callback controller for your identity provider like you normally would with OmniAuth.
31
+ 1. Configure your routes to handle routes for multiple identity provider instances.
32
+ 1. Configure omniauth-multi-provider to choose the appropriate identity provider instance.
27
33
 
28
- TODO: Write usage instructions here
34
+ ### Configure Routes
35
+
36
+ Add something like the following to your routes assuming you're using Rails and a SAML identity provider
37
+ (your actual URL structure may vary):
38
+
39
+ ```ruby
40
+ MyApplication::Application.routes.draw do
41
+ match '/auth/saml/:identity_provider_id/callback',
42
+ via: [:get, :post],
43
+ to: 'omniauth_callbacks#saml',
44
+ as: 'user_omniauth_callback'
45
+
46
+ match '/auth/saml/:identity_provider_id',
47
+ via: [:get, :post],
48
+ to: 'omniauth_callbacks#passthru',
49
+ as: 'user_omniauth_authorize'
50
+ end
51
+ ```
52
+
53
+ ### Configure OmniAuth
54
+
55
+ The basic configuration of OmniAuth looks something like this:
56
+
57
+ ```ruby
58
+ # config/omniauth.rb
59
+ Rails.application.config.middleware.use OmniAuth::Builder do
60
+ OmniAuth::MultiProvider.register(self,
61
+ provider_name: :saml,
62
+ identity_provider_id_regex: /\d+/,
63
+ path_prefix: '/auth/saml',
64
+ callback_suffix: 'callback',
65
+ # Specify any additional provider specific options
66
+ name_identifier_format: 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
67
+ issuer: 'salsify.com',
68
+ allowed_clock_drift: 5.seconds) do |identity_provider_id, rack_env|
69
+ identity_provider = SAML::IdentityProvider.find(identity_provider_id)
70
+ # Optionally store a reference to the identity provider in the Rack environment
71
+ # so you can reference it in your OmniAuth callbacks controller
72
+ rack_env['salsify.saml_identity_provider'] = identity_provider
73
+ # Any dynamic options returned by this block will be merged in with any statically
74
+ # configured options for the identity provider type e.g. issuer in this example.
75
+ identity_provider.options
76
+ end
77
+
78
+ # This also works with multiple provider types
79
+ OmniAuth::MultiProvider.register(self,
80
+ provider_name: :oauth2,
81
+ identity_provider_id_regex: /\d+/,
82
+ path_prefix: '/auth/oauth2') do |identity_provider_id, rack_env|
83
+ identity_provider = OAuth2::IdentityProvider.find(identity_provider_id)
84
+ rack_env['salsify.oauth2_identity_provider'] = identity_provider
85
+ identity_provider.options
86
+ end
87
+ end
88
+ ```
29
89
 
30
90
  ## Development
31
91
 
@@ -1,3 +1,5 @@
1
+ require 'omniauth'
2
+
1
3
  require 'omni_auth/multi_provider/handler'
2
4
  require 'omni_auth/multi_provider/version'
3
5
 
@@ -6,11 +8,10 @@ module OmniAuth
6
8
  def self.register(builder,
7
9
  provider_name:,
8
10
  path_prefix: ::OmniAuth.config.path_prefix,
9
- identity_provider_id_regex:,
10
11
  **options, &dynamic_options_generator)
11
12
 
12
13
  handler = OmniAuth::MultiProvider::Handler.new(path_prefix: path_prefix,
13
- identity_provider_id_regex: identity_provider_id_regex,
14
+ **options,
14
15
  &dynamic_options_generator)
15
16
 
16
17
  static_options = options.merge(path_prefix: path_prefix)
@@ -2,23 +2,25 @@ module OmniAuth
2
2
  module MultiProvider
3
3
  class Handler
4
4
  attr_reader :path_prefix, :provider_instance_path_regex, :request_path_regex,
5
- :callback_path_regex, :provider_path_prefix,
5
+ :callback_path_regex, :callback_suffix,
6
6
  :identity_provider_options_generator
7
7
 
8
- def initialize(path_prefix: OmniAuth.config.path_prefix,
9
- identity_provider_id_regex: /\w+/,
10
- &provider_generator)
8
+ def initialize(path_prefix:,
9
+ identity_provider_id_regex:,
10
+ callback_suffix: 'callback',
11
+ **_options,
12
+ &identity_provider_options_generator)
11
13
  raise 'Missing provider options generator block' unless block_given?
12
14
 
13
15
  @path_prefix = path_prefix
14
- @identity_provider_options_generator = provider_generator
16
+ @identity_provider_options_generator = identity_provider_options_generator
15
17
  @identity_provider_id_regex = identity_provider_id_regex
18
+ @callback_suffix = callback_suffix
16
19
 
17
20
  # Eagerly compute these since lazy evaluation will not be threadsafe
18
- @provider_path_prefix = @path_prefix
19
21
  @provider_instance_path_regex = /^#{@path_prefix}\/(?<identity_provider_id>#{@identity_provider_id_regex})/
20
22
  @request_path_regex = /#{@provider_instance_path_regex}\/?$/
21
- @callback_path_regex = /#{@provider_instance_path_regex}\/callback\/?$/
23
+ @callback_path_regex = /#{@provider_instance_path_regex}\/#{@callback_suffix}\/?$/
22
24
  end
23
25
 
24
26
  def provider_options
@@ -29,6 +31,16 @@ module OmniAuth
29
31
  }
30
32
  end
31
33
 
34
+ def request_path?(env)
35
+ path = current_path(env)
36
+ !!request_path_regex.match(path)
37
+ end
38
+
39
+ def callback_path?(env)
40
+ path = current_path(env)
41
+ !!callback_path_regex.match(path)
42
+ end
43
+
32
44
  def setup(env)
33
45
  identity_provider_id = extract_identity_provider_id(env)
34
46
  if identity_provider_id
@@ -38,10 +50,12 @@ module OmniAuth
38
50
  end
39
51
  end
40
52
 
53
+ private
54
+
41
55
  def add_path_options(strategy, identity_provider_id)
42
56
  strategy.options.merge!(
43
- request_path: "#{provider_path_prefix}/#{identity_provider_id}",
44
- callback_path: "#{provider_path_prefix}/#{identity_provider_id}/callback"
57
+ request_path: "#{path_prefix}/#{identity_provider_id}",
58
+ callback_path: "#{path_prefix}/#{identity_provider_id}/#{callback_suffix}"
45
59
  )
46
60
  end
47
61
 
@@ -53,16 +67,6 @@ module OmniAuth
53
67
  throw :warden, result
54
68
  end
55
69
 
56
- def request_path?(env)
57
- path = current_path(env)
58
- !!request_path_regex.match(path)
59
- end
60
-
61
- def callback_path?(env)
62
- path = current_path(env)
63
- !!callback_path_regex.match(path)
64
- end
65
-
66
70
  def current_path(env)
67
71
  env['PATH_INFO']
68
72
  end
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module MultiProvider
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'bundler', '~> 1.12'
33
33
  spec.add_development_dependency 'rake', '~> 10.0'
34
34
  spec.add_development_dependency 'rspec', '~> 3.4'
35
- spec.add_development_dependency 'salsify_rubocop', '~> 0.42.0'
35
+ spec.add_development_dependency 'salsify_rubocop', '~> 0.45.0'
36
36
  spec.add_development_dependency 'overcommit'
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-multi-provider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-09 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.42.0
75
+ version: 0.45.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.42.0
82
+ version: 0.45.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: overcommit
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +107,8 @@ files:
107
107
  - ".overcommit.yml"
108
108
  - ".rspec"
109
109
  - ".rubocop.yml"
110
+ - ".ruby-gemset"
111
+ - ".ruby-version"
110
112
  - ".travis.yml"
111
113
  - CHANGELOG.md
112
114
  - Gemfile