omniauth-multi-provider 0.1.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
+ SHA1:
3
+ metadata.gz: 16ff3ef4f047ef105e33b3e2442420c39eb867ea
4
+ data.tar.gz: c5572a21ca416dc901a6c2d4e8ba3a3a09174ee3
5
+ SHA512:
6
+ metadata.gz: 2c153418eb8f3c8f6a356a3905f159afd2715b362c3d07160a23d8bc97aa0c376566f7a78bdd7fffc65d5bb5ea2c421d17bde8b9788162d98f6088256e4ab497
7
+ data.tar.gz: 43de8c2fbfe2dfacf2aa67b95d9a674dc99cbfc8dea9e8c9315219b83f2ac78714dafb5e9e5434a4e35932a0b346ad37abb462e3d5c1126dbdbbdd519b06c15a
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.overcommit.yml ADDED
@@ -0,0 +1,13 @@
1
+ PreCommit:
2
+ RuboCop:
3
+ enabled: true
4
+ required: false
5
+ on_warn: fail
6
+
7
+ HardTabs:
8
+ enabled: true
9
+ required: false
10
+
11
+ CommitMsg:
12
+ TrailingPeriod:
13
+ enabled: false
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ salsify_rubocop: conf/rubocop.yml
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ before_install: gem install bundler -v 1.12.4
5
+ script:
6
+ - bundle exec rubocop
7
+ - bundle exec rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # omniauth-multi-provider
2
+
3
+ ## v0.1.0
4
+ - Initial version
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ # override the :github shortcut to be secure by using HTTPS
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
6
+
7
+ # Specify your gem's dependencies in omniauth-multi-provider.gemspec
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Salsify, Inc
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.
22
+
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # OmniAuth::MultiProvider
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
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'omniauth-multi-provider'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install omniauth-multi-provider
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
33
+ run `rake spec` to run the tests. You can also run `bin/console` for an
34
+ interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`.
37
+
38
+ To release a new version, update the version number in `version.rb`, and then
39
+ run `bundle exec rake release`, which will create a git tag for the version,
40
+ push git commits and tags, and push the `.gem` file to
41
+ [rubygems.org](https://rubygems.org)
42
+ .
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at
47
+ https://github.com/salsify/omniauth-multi-provider.## License
48
+
49
+ The gem is available as open source under the terms of the
50
+ [MIT License](http://opensource.org/licenses/MIT).
51
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'omniauth-multi-provider'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -v
5
+
6
+ bundle update
7
+
8
+ overcommit --install
@@ -0,0 +1,21 @@
1
+ require 'omni_auth/multi_provider/handler'
2
+ require 'omni_auth/multi_provider/version'
3
+
4
+ module OmniAuth
5
+ module MultiProvider
6
+ def self.register(builder,
7
+ provider_name:,
8
+ path_prefix: ::OmniAuth.config.path_prefix,
9
+ identity_provider_id_regex:,
10
+ **options, &dynamic_options_generator)
11
+
12
+ handler = OmniAuth::MultiProvider::Handler.new(path_prefix: path_prefix,
13
+ identity_provider_id_regex: identity_provider_id_regex,
14
+ &dynamic_options_generator)
15
+
16
+ static_options = options.merge(path_prefix: path_prefix)
17
+
18
+ builder.provider(provider_name, static_options.merge(handler.provider_options))
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,77 @@
1
+ module OmniAuth
2
+ module MultiProvider
3
+ class Handler
4
+ attr_reader :path_prefix, :provider_instance_path_regex, :request_path_regex,
5
+ :callback_path_regex, :provider_path_prefix,
6
+ :identity_provider_options_generator
7
+
8
+ def initialize(path_prefix: OmniAuth.config.path_prefix,
9
+ identity_provider_id_regex: /\w+/,
10
+ &provider_generator)
11
+ raise 'Missing provider options generator block' unless block_given?
12
+
13
+ @path_prefix = path_prefix
14
+ @identity_provider_options_generator = provider_generator
15
+ @identity_provider_id_regex = identity_provider_id_regex
16
+
17
+ # Eagerly compute these since lazy evaluation will not be threadsafe
18
+ @provider_path_prefix = @path_prefix
19
+ @provider_instance_path_regex = /^#{@path_prefix}\/(?<identity_provider_id>#{@identity_provider_id_regex})/
20
+ @request_path_regex = /#{@provider_instance_path_regex}\/?$/
21
+ @callback_path_regex = /#{@provider_instance_path_regex}\/callback\/?$/
22
+ end
23
+
24
+ def provider_options
25
+ {
26
+ request_path: method(:request_path?),
27
+ callback_path: method(:callback_path?),
28
+ setup: method(:setup)
29
+ }
30
+ end
31
+
32
+ def setup(env)
33
+ identity_provider_id = extract_identity_provider_id(env)
34
+ if identity_provider_id
35
+ strategy = env['omniauth.strategy']
36
+ add_path_options(strategy, identity_provider_id)
37
+ add_identity_provider_options(strategy, env, identity_provider_id)
38
+ end
39
+ end
40
+
41
+ def add_path_options(strategy, identity_provider_id)
42
+ strategy.options.merge!(
43
+ request_path: "#{provider_path_prefix}/#{identity_provider_id}",
44
+ callback_path: "#{provider_path_prefix}/#{identity_provider_id}/callback"
45
+ )
46
+ end
47
+
48
+ def add_identity_provider_options(strategy, env, identity_provider_id)
49
+ identity_provider_options = identity_provider_options_generator.call(identity_provider_id, env) || {}
50
+ strategy.options.merge!(identity_provider_options)
51
+ rescue => e
52
+ result = strategy.fail!(:invalid_identity_provider, e)
53
+ throw :warden, result
54
+ end
55
+
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
+ def current_path(env)
67
+ env['PATH_INFO']
68
+ end
69
+
70
+ def extract_identity_provider_id(env)
71
+ path = current_path(env)
72
+ match = provider_instance_path_regex.match(path)
73
+ match ? match[:identity_provider_id] : nil
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module MultiProvider
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ # rubocop:disable Style/FileName
2
+ require 'omni_auth/multi_provider'
3
+ # rubocop:enable Style/FileName
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omni_auth/multi_provider/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'omniauth-multi-provider'
8
+ spec.version = OmniAuth::MultiProvider::VERSION
9
+ spec.authors = ['Salsify, Inc']
10
+ spec.email = ['engineering@salsify.com']
11
+
12
+ spec.summary = 'OmniAuth support for multiple providers of an authentication strategy'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/salsify/omniauth-multi-provider'
15
+
16
+ spec.license = 'MIT'
17
+
18
+ # Set 'allowed_push_post' to control where this gem can be published.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'bin'
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'omniauth'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.12'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.4'
35
+ spec.add_development_dependency 'salsify_rubocop', '~> 0.42.0'
36
+ spec.add_development_dependency 'overcommit'
37
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-multi-provider
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Salsify, Inc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: salsify_rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.42.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.42.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: overcommit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: OmniAuth support for multiple providers of an authentication strategy
98
+ email:
99
+ - engineering@salsify.com
100
+ executables:
101
+ - console
102
+ - setup
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".overcommit.yml"
108
+ - ".rspec"
109
+ - ".rubocop.yml"
110
+ - ".travis.yml"
111
+ - CHANGELOG.md
112
+ - Gemfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/omni_auth/multi_provider.rb
119
+ - lib/omni_auth/multi_provider/handler.rb
120
+ - lib/omni_auth/multi_provider/version.rb
121
+ - lib/omniauth-multi-provider.rb
122
+ - omniauth-multi-provider.gemspec
123
+ homepage: https://github.com/salsify/omniauth-multi-provider
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ allowed_push_host: https://rubygems.org
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.5.1
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: OmniAuth support for multiple providers of an authentication strategy
148
+ test_files: []