omniauth-apihub 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a8ae07e642fc34b2dae0481a824316ae0ac4d23b
4
+ data.tar.gz: 2a9569d662afa18a083b2eb406a53484a1ead89d
5
+ SHA512:
6
+ metadata.gz: c98dda403c0b531d89c5d1c8abc4fd6059a0ce612e5e384ac85371d53192e60afe690e5fe33263184d38086b7bae41dd766e7bf854b60cb396883b6492049b21
7
+ data.tar.gz: c9de2e99a3a7aefd659d70f80df21f972126db9377509949cdeffb8ac980a6454a6a8b2e8189723fd8acab435a79e9c183b4f350dcf81284a209fd7445084770
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-apihub.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # OmniAuth ApiHub
2
+
3
+ This is the OmniAuth strategy for authenticating to [Api Gateway](https://github.com/apihub/apigateway).
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ Rails.application.config.middleware.use OmniAuth::Builder do
9
+ provider :apihub, ENV['APIHUB_CLIENT_ID'], ENV['APIHUB_CLIENT_SECRET'], { site: ENV['APIHUB_SITE'], authorize_url: ENV['APIHUB_AUTHORIZE_URL'], token_url: ENV['APIHUB_TOKEN_URL'] }
10
+ end
11
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Run specs'
8
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth-apihub/version"
2
+ require 'omniauth/strategies/apihub'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module ApiHub
3
+ VERSION = "0.0.6"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ module OmniAuth
2
+ module ApiHub
3
+ class Client
4
+ def self.client_options(options)
5
+ ok = %w{site authorize_url token_url}.all? {|param| options.include?(param.to_sym) }
6
+ raise ArgumentError, 'Missing required parameters.' unless ok
7
+
8
+ {
9
+ site: options[:site],
10
+ authorize_url: options[:authorize_url],
11
+ token_url: options[:token_url]
12
+ }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ require 'omniauth-oauth2'
2
+ require "omniauth/apihub/client"
3
+ require 'base64'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class ApiHub < OmniAuth::Strategies::OAuth2
8
+ option :name, 'apihub'
9
+ option :client_options, nil
10
+
11
+ uid { raw_info['email'].to_s }
12
+
13
+ info do
14
+ {
15
+ name: raw_info['name'],
16
+ email: raw_info['email'],
17
+ username: raw_info['username']
18
+ }
19
+ end
20
+
21
+ extra do
22
+ {
23
+ raw_info: raw_info
24
+ }
25
+ end
26
+
27
+ def initialize(app, *args, &block)
28
+ super(app, *args, &block)
29
+ options[:client_options] = OmniAuth::ApiHub::Client.client_options(options) if options.client_options.nil?
30
+ end
31
+
32
+ def raw_info
33
+ payload = access_token.get('me').parsed
34
+ @raw_info ||= payload['user']
35
+ end
36
+
37
+ def build_access_token
38
+ options.token_params.merge!(:headers => {'Authorization' => basic_auth_header })
39
+ super
40
+ end
41
+
42
+ private
43
+ def basic_auth_header
44
+ "Basic " + Base64.strict_encode64("#{options[:client_id]}:#{options[:client_secret]}")
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/omniauth-apihub/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "omniauth-apihub"
6
+ spec.version = OmniAuth::ApiHub::VERSION
7
+ spec.license = "MIT"
8
+
9
+ spec.authors = ["Alberto Leal"]
10
+ spec.email = ["albertonb@gmail.com"]
11
+ spec.description = %q{ApiHub OAuth2 Strategy for OmniAuth.}
12
+ spec.summary = %q{ApiHub OAuth2 Strategy for OmniAuth.}
13
+ spec.homepage = "https://github.com/apihub/omniauth-apihub"
14
+
15
+ spec.files = `git ls-files`.split($/)
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_development_dependency 'bundler', '~> 1.3'
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency 'rack-test'
23
+ spec.add_development_dependency 'rspec', '~> 2.7'
24
+ spec.add_development_dependency 'simplecov'
25
+ spec.add_development_dependency 'webmock'
26
+
27
+ spec.add_dependency 'omniauth-oauth2', '~> 1.1.2'
28
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::ApiHub::Client do
4
+ let(:options) {
5
+ {
6
+ site: 'https://apihub.example.org',
7
+ authorize_url: 'https://apihub.example.org/login/oauth/authorize',
8
+ token_url: 'https://apihub.example.org/login/oauth/access_token'
9
+ }
10
+ }
11
+ it "raises an exception when missing required params" do
12
+ expect{ OmniAuth::ApiHub::Client.client_options }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ it "returns client_options struture for omniauth" do
16
+ expect(OmniAuth::ApiHub::Client.client_options(options)).to eq options
17
+ end
18
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::ApiHub do
4
+ let(:access_token) { double('AccessToken', options: {}) }
5
+ let(:user) { double('User') }
6
+ let(:parsed_response) { double('Parsed Response', :[] => user) }
7
+ let(:response) { double('Response', :parsed => parsed_response) }
8
+
9
+ let(:apihub) do
10
+ OmniAuth::Strategies::ApiHub.new('CLIENT_ID', 'CLIENT_SECRET',{
11
+ client_options: {
12
+ site: 'https://apihub.example.org',
13
+ authorize_url: 'https://apihub.example.org/login/oauth/authorize',
14
+ token_url: 'https://apihub.example.org/login/oauth/access_token'
15
+ }
16
+ }
17
+ )
18
+ end
19
+
20
+ subject do
21
+ OmniAuth::Strategies::ApiHub.new({})
22
+ end
23
+
24
+ context "client options" do
25
+ it 'raises an exception if required params are not provided' do
26
+ expect{ subject }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ describe "initializiation" do
30
+ it "site endpoint" do
31
+ expect(apihub.options.client_options.site).to eq('https://apihub.example.org')
32
+ end
33
+
34
+ it "authorize url endpoint" do
35
+ expect(apihub.options.client_options.authorize_url).to eq('https://apihub.example.org/login/oauth/authorize')
36
+ end
37
+
38
+ it "token endpoint" do
39
+ expect(apihub.options.client_options.token_url).to eq('https://apihub.example.org/login/oauth/access_token')
40
+ end
41
+ end
42
+ end
43
+
44
+ context "#raw_info" do
45
+ it "returns user info" do
46
+ allow(apihub).to receive(:access_token).and_return(access_token)
47
+ allow(access_token).to receive(:get).with('me').and_return(response)
48
+ expect(apihub.raw_info).to eq(user)
49
+ end
50
+ end
51
+
52
+ context "info" do
53
+ before(:each) do
54
+ allow(apihub).to receive(:raw_info).and_return({})
55
+ end
56
+
57
+ it "has name key" do
58
+ expect(apihub.info).to have_key(:name)
59
+ end
60
+
61
+ it "has email key" do
62
+ expect(apihub.info).to have_key(:email)
63
+ end
64
+
65
+ it "has username key" do
66
+ expect(apihub.info).to have_key(:username)
67
+ end
68
+ end
69
+
70
+ context "extra" do
71
+ it "returns raw user info" do
72
+ allow(apihub).to receive(:raw_info).and_return({ name: 'Alice', username: 'alice', email: 'alice@example.org'})
73
+
74
+ expect(apihub.extra).to have_key(:raw_info)
75
+ %w{name username email}.each do |k|
76
+ expect(apihub.extra[:raw_info]).to have_key(k.to_sym)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+ require 'rspec'
7
+ require 'rack/test'
8
+ require 'webmock/rspec'
9
+ require 'omniauth'
10
+ require 'omniauth-apihub'
11
+
12
+ RSpec.configure do |config|
13
+ config.include WebMock::API
14
+ config.include Rack::Test::Methods
15
+ config.extend OmniAuth::Test::StrategyMacros, type: :strategy
16
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-apihub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Alberto Leal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
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
+ - !ruby/object:Gem::Dependency
98
+ name: omniauth-oauth2
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.1.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.1.2
111
+ description: ApiHub OAuth2 Strategy for OmniAuth.
112
+ email:
113
+ - albertonb@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - lib/omniauth-apihub.rb
124
+ - lib/omniauth-apihub/version.rb
125
+ - lib/omniauth/apihub/client.rb
126
+ - lib/omniauth/strategies/apihub.rb
127
+ - omniauth-apihub.gemspec
128
+ - spec/omniauth/apihub/client_spec.rb
129
+ - spec/omniauth/strategies/apihub_spec.rb
130
+ - spec/spec_helper.rb
131
+ homepage: https://github.com/apihub/omniauth-apihub
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.2.2
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: ApiHub OAuth2 Strategy for OmniAuth.
155
+ test_files:
156
+ - spec/omniauth/apihub/client_spec.rb
157
+ - spec/omniauth/strategies/apihub_spec.rb
158
+ - spec/spec_helper.rb