omniauth-provider_registry 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +9 -0
- data/lib/omniauth/provider_registry.rb +25 -0
- data/lib/omniauth/provider_registry/rack_middleware_source.rb +9 -0
- data/lib/omniauth/provider_registry/rails_middleware_source.rb +25 -0
- data/lib/omniauth/provider_registry/registry.rb +23 -0
- data/lib/omniauth/provider_registry/version.rb +5 -0
- data/omniauth-provider_registry.gemspec +24 -0
- data/spec/provider_registry_spec.rb +30 -0
- data/spec/rails_middleware_source_spec.rb +94 -0
- data/spec/registry_spec.rb +35 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c32c19d94554fc08b000e1eec80173685d24a7b
|
4
|
+
data.tar.gz: d7b487fa28c965bdf7271e039df49e3db1b5a090
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5216d8afd696c41ba90b591465108b2d542ce4a51771385273e8ae3b78ac6030414ee3403e7432c73730bd49b4815b294f1b7db50f6194327a1bd7026fa8520f
|
7
|
+
data.tar.gz: a5f9a791cc8b4a55b12e1ad72695b2d6741a263484d7971932f505026dc6fc7bb63901766b97a47e5398f2afcca710018254cf19e9e370b844b1ed128f54ad37
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.ruby-gemset
|
24
|
+
.ruby-version
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Joshua Flanagan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# OmniAuth::ProviderRegistry
|
2
|
+
|
3
|
+
Provides access to your application's configured OmniAuth providers
|
4
|
+
|
5
|
+
## Motivation
|
6
|
+
|
7
|
+
Your configured providers contain a lot of information that may be useful in
|
8
|
+
other parts of your application. Sometimes you specify the information when you
|
9
|
+
configure the provider, so you already have access to it. But there is also
|
10
|
+
some information built into the strategy itself, that is not easy to access.
|
11
|
+
|
12
|
+
The `ProviderRegistry` allows you to retrieve all information available for
|
13
|
+
your configured strategies.
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```
|
18
|
+
configured_provider = OmniAuth::ProviderRegistry.find(:github)
|
19
|
+
configured_provider.options.client_id # 1234567890123234
|
20
|
+
configured_provider.options.client_options.site # https://api.github.com
|
21
|
+
```
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'omniauth-provider_registry'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install omniauth-provider_registry
|
36
|
+
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/joshuaflanagan/omniauth-provider_registry/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'omniauth'
|
2
|
+
require "omniauth/provider_registry/version"
|
3
|
+
require "omniauth/provider_registry/registry"
|
4
|
+
require "omniauth/provider_registry/rack_middleware_source"
|
5
|
+
require "omniauth/provider_registry/rails_middleware_source"
|
6
|
+
|
7
|
+
module OmniAuth
|
8
|
+
module ProviderRegistry
|
9
|
+
def self.find(name)
|
10
|
+
registry.find(name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.registry
|
14
|
+
@registry ||= Registry.new(source.providers)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.source
|
18
|
+
if defined?(Rails)
|
19
|
+
RailsMiddlewareSource
|
20
|
+
else
|
21
|
+
RackMiddlewareSource
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'omniauth'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module ProviderRegistry
|
5
|
+
class RailsMiddlewareSource
|
6
|
+
def self.providers
|
7
|
+
new(Rails.application.config.middleware).providers
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(middlewares)
|
11
|
+
@middlewares = middlewares
|
12
|
+
end
|
13
|
+
|
14
|
+
def providers
|
15
|
+
builders = @middlewares.select{|m| m === OmniAuth::Builder }.flat_map{|b|
|
16
|
+
b.build(nil).instance_variable_get(:@use)
|
17
|
+
}
|
18
|
+
direct = @middlewares.select{|m| m.klass.is_a?(Class) && m.klass <= OmniAuth::Strategy}.map{|s|
|
19
|
+
->{ s.build(nil) }
|
20
|
+
}
|
21
|
+
builders + direct
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module ProviderRegistry
|
3
|
+
class Registry
|
4
|
+
attr_reader :factory_methods
|
5
|
+
|
6
|
+
def initialize(factory_methods)
|
7
|
+
@factory_methods = factory_methods
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(name)
|
11
|
+
factory = factories_by_name[name.to_sym]
|
12
|
+
factory.call if factory
|
13
|
+
end
|
14
|
+
|
15
|
+
def factories_by_name
|
16
|
+
@factories_by_name ||= factory_methods.each_with_object({}){|f, all|
|
17
|
+
name = f.call.name.to_sym
|
18
|
+
all[name] = f
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth/provider_registry/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omniauth-provider_registry"
|
8
|
+
spec.version = OmniAuth::ProviderRegistry::VERSION
|
9
|
+
spec.authors = ["Joshua Flanagan"]
|
10
|
+
spec.email = ["joshuaflanagan@gmail.com"]
|
11
|
+
spec.summary = %q{Provides access to your configured OmniAuth providers}
|
12
|
+
spec.homepage = "https://github.com/joshuaflanagan/omniauth-provider_registry"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'omniauth', '~> 1.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'omniauth/provider_registry'
|
3
|
+
|
4
|
+
describe OmniAuth::ProviderRegistry do
|
5
|
+
describe "determining the source of providers" do
|
6
|
+
it "uses RailsMiddlewareSource in Rails application" do
|
7
|
+
Rails = OpenStruct.new(application: Object.new)
|
8
|
+
|
9
|
+
source = OmniAuth::ProviderRegistry.source
|
10
|
+
|
11
|
+
source.must_equal OmniAuth::ProviderRegistry::RailsMiddlewareSource
|
12
|
+
end
|
13
|
+
|
14
|
+
it "uses RackMiddlewareSource when not in Rails application" do
|
15
|
+
source = OmniAuth::ProviderRegistry.source
|
16
|
+
|
17
|
+
source.must_equal OmniAuth::ProviderRegistry::RackMiddlewareSource
|
18
|
+
end
|
19
|
+
|
20
|
+
before do
|
21
|
+
@original_rails_const = Object.__send__(:remove_const, :Rails) if defined?(Rails)
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
Object.__send__(:remove_const, :Rails) if defined?(Rails)
|
26
|
+
Object.__send__(:const_set, "Rails", @original_rails_const) if @original_rails_const
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'omniauth/provider_registry/rails_middleware_source'
|
3
|
+
require 'action_dispatch/middleware/stack'
|
4
|
+
|
5
|
+
describe OmniAuth::ProviderRegistry::RailsMiddlewareSource do
|
6
|
+
def configured_middlewares
|
7
|
+
@configured_middlewares ||=
|
8
|
+
begin
|
9
|
+
stack = ActionDispatch::MiddlewareStack.new
|
10
|
+
stack.use UnrelatedMiddleware1
|
11
|
+
stack.use Strength
|
12
|
+
stack.use OmniAuth::Builder do
|
13
|
+
provider ConfiguredViaBuilder1, "X", "Y"
|
14
|
+
provider :configured_via_builder2, "A", "B"
|
15
|
+
end
|
16
|
+
stack.use Charisma, "CLIENT_ID", "SECRET"
|
17
|
+
stack.use UnrelatedMiddleware2
|
18
|
+
stack.use OmniAuth::Builder do
|
19
|
+
provider ConfiguredViaBuilder3
|
20
|
+
end
|
21
|
+
stack.use Dexterity, "CLIENT_ID", "SECRET", favorite_color: "red"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'byebug'
|
26
|
+
it "returns factory methods for all OmniAuth middleware" do
|
27
|
+
source = OmniAuth::ProviderRegistry::RailsMiddlewareSource.new(configured_middlewares)
|
28
|
+
provider_factories = source.providers
|
29
|
+
provider_factories.length.must_equal 6
|
30
|
+
provider_factories.each do |factory|
|
31
|
+
factory.must_respond_to :call
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "factory methods successfully return instances of strategies" do
|
36
|
+
source = OmniAuth::ProviderRegistry::RailsMiddlewareSource.new(configured_middlewares)
|
37
|
+
instances = source.providers.map{|p| p.call }
|
38
|
+
instances.length.must_equal 6
|
39
|
+
instances.each do |configured_provider|
|
40
|
+
configured_provider.must_be_kind_of OmniAuth::Strategy
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "providers added via 'use' have their configured values" do
|
45
|
+
stack = ActionDispatch::MiddlewareStack.new
|
46
|
+
stack.use Dexterity, "lorem", "ipsum",
|
47
|
+
favorite_color: "green", favorite_number: 5
|
48
|
+
|
49
|
+
source = OmniAuth::ProviderRegistry::RailsMiddlewareSource.new(stack)
|
50
|
+
provider = source.providers.first.call
|
51
|
+
provider.options["arg1"].must_equal "lorem"
|
52
|
+
provider.options["arg2"].must_equal "ipsum"
|
53
|
+
provider.options["site"].must_equal "http://example.com"
|
54
|
+
provider.options["favorite_color"].must_equal "green"
|
55
|
+
provider.options["favorite_number"].must_equal 5
|
56
|
+
end
|
57
|
+
|
58
|
+
it "providers added via OmniAuth::Builder have their configured values" do
|
59
|
+
stack = ActionDispatch::MiddlewareStack.new
|
60
|
+
stack.use OmniAuth::Builder do
|
61
|
+
provider Dexterity, "lorem", "ipsum",
|
62
|
+
favorite_color: "green", favorite_number: 5
|
63
|
+
end
|
64
|
+
source = OmniAuth::ProviderRegistry::RailsMiddlewareSource.new(stack)
|
65
|
+
provider = source.providers.first.call
|
66
|
+
provider.options["arg1"].must_equal "lorem"
|
67
|
+
provider.options["arg2"].must_equal "ipsum"
|
68
|
+
provider.options["site"].must_equal "http://example.com"
|
69
|
+
provider.options["favorite_color"].must_equal "green"
|
70
|
+
provider.options["favorite_number"].must_equal 5
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class FakeStrategy
|
75
|
+
include OmniAuth::Strategy
|
76
|
+
args [:first_arg, :second_arg]
|
77
|
+
end
|
78
|
+
|
79
|
+
class Strength < FakeStrategy; end
|
80
|
+
class Charisma < FakeStrategy; end
|
81
|
+
class Dexterity < FakeStrategy
|
82
|
+
include OmniAuth::Strategy
|
83
|
+
args [:arg1, :arg2]
|
84
|
+
option :site, "http://example.com"
|
85
|
+
option :favorite_color, "blue"
|
86
|
+
end
|
87
|
+
|
88
|
+
class ConfiguredViaBuilder1 < FakeStrategy; end
|
89
|
+
class OmniAuth::Strategies::ConfiguredViaBuilder2 < FakeStrategy; end
|
90
|
+
class ConfiguredViaBuilder3
|
91
|
+
include OmniAuth::Strategy
|
92
|
+
end
|
93
|
+
class UnrelatedMiddleware1; end
|
94
|
+
class UnrelatedMiddleware2; end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'omniauth/provider_registry/registry'
|
3
|
+
|
4
|
+
describe OmniAuth::ProviderRegistry::Registry do
|
5
|
+
describe "when asked to find a provider it doesn't know about" do
|
6
|
+
it "returns nil" do
|
7
|
+
registry = OmniAuth::ProviderRegistry::Registry.new([])
|
8
|
+
registry.find(:unknown_provider).must_be_nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "when asked to find a provider it does know about" do
|
13
|
+
def provider_factories
|
14
|
+
@provider_factories ||= [
|
15
|
+
-> { OpenStruct.new(name: "red") },
|
16
|
+
-> { OpenStruct.new(name: "orange") },
|
17
|
+
-> { OpenStruct.new(name: "yellow") },
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns an instance of a configured strategy" do
|
22
|
+
registry = OmniAuth::ProviderRegistry::Registry.new(provider_factories)
|
23
|
+
provider = registry.find("orange")
|
24
|
+
|
25
|
+
provider.wont_be_nil
|
26
|
+
provider.name.to_s.must_equal "orange"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "finds instances by symbol name" do
|
30
|
+
registry = OmniAuth::ProviderRegistry::Registry.new(provider_factories)
|
31
|
+
provider = registry.find(:orange)
|
32
|
+
provider.wont_be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-provider_registry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua Flanagan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-15 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: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.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.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- joshuaflanagan@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/omniauth/provider_registry.rb
|
68
|
+
- lib/omniauth/provider_registry/rack_middleware_source.rb
|
69
|
+
- lib/omniauth/provider_registry/rails_middleware_source.rb
|
70
|
+
- lib/omniauth/provider_registry/registry.rb
|
71
|
+
- lib/omniauth/provider_registry/version.rb
|
72
|
+
- omniauth-provider_registry.gemspec
|
73
|
+
- spec/provider_registry_spec.rb
|
74
|
+
- spec/rails_middleware_source_spec.rb
|
75
|
+
- spec/registry_spec.rb
|
76
|
+
homepage: https://github.com/joshuaflanagan/omniauth-provider_registry
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.2.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Provides access to your configured OmniAuth providers
|
100
|
+
test_files:
|
101
|
+
- spec/provider_registry_spec.rb
|
102
|
+
- spec/rails_middleware_source_spec.rb
|
103
|
+
- spec/registry_spec.rb
|