omniauth-samaritan 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTg1ZmMwZGQ4MmVhYjkyNTIwMTdkYmJkZDM3YjhkZjY2M2ZiOGRlMg==
4
+ ZmQ2ZmViOGY0YjhjOGI3YzQyZTFiYjBkYWNjNzBlMDMwMDk0ZmE3Zg==
5
5
  data.tar.gz: !binary |-
6
- NzdiNTQ1OTcyMzJmMzgzNWQzOTBiNTFiZDM2M2E2YmFhMTIyN2U1Mw==
6
+ OTQ1YTZjYTUxOWVhNmNkNGI1YjAzNjBiMjhmMTljY2M4MDQ3ZTk1ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjUzYTFkMGU1YWRhMTIzYmQxNDczMDE3NzJjZDJjZjUwYjczYzNiOGMyNDZl
10
- OWNiZDY5MmZhZjUzNThmYWVhMDhjODk1ZmI2OThlNDZiYmFlMmY4MDliZGY2
11
- NmE5MGYwYjZhZTZhMzBjYTY0ZWI4ZThkNGY3NDZhNjUxZDgwMGQ=
9
+ ODQ3M2M5NzcwZDYzNzlmMmVmZDI3YjVjZTdlYWVhYTA4ZWM2NDRkZDBlYTY4
10
+ ZGU4MjZkZDgwZDIzN2I4YTQ2ZDZkY2ZjOWRhOTA4MTExY2ZmMjM3NTU2MGVm
11
+ MDg3NWQ3ZGI1ZTI2NDc1MDk2NmVhMWI1ODQzOTUwNzUyZWM5ZjA=
12
12
  data.tar.gz: !binary |-
13
- NWY5YWExOGU3YjYzODAxZmEyZTcxZjZlYmViNTI0NGJhMjM2Y2EyNDk2MzQ3
14
- MjJmZWUwMGU3MzRhNzI0ZDI4NzQwYjc0NTUzZGNjMzEyODk4NTE4N2U2MTc1
15
- YTY1ZWNiZGQxOTA2ZTgzMTI5NzE1NWUxYjFhNTQyNTM1YzI0Y2Y=
13
+ YTg1ZTk3ODEwODU5N2YzMjQxMjdiNjM3OWNjNjY0OWQyNGQxN2ZkZGUyNWNk
14
+ YmU0M2UwMTBiYmMwOWM2ZWQzMmMyY2RjYTM5MTJlZDIzOTI3OTJkYmRhM2Y3
15
+ ZDE3Y2NiOTg1MDU1NTQwOGQzY2ZlNmYxMjA3N2Y3Yzc4ZmJjOGQ=
data/.gitignore CHANGED
@@ -1,22 +1,22 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- .ruby-gemset
7
- .ruby-version
8
- .rvmrc
9
- Gemfile.lock
10
- InstalledFiles
11
- _yardoc
12
- coverage
13
- doc/
14
- lib/bundler/man
15
- pkg
16
- rdoc
17
- spec/reports
18
- test/tmp
19
- test/version_tmp
20
- tmp
21
- .powenv
22
- .idea/
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-gemset
7
+ .ruby-version
8
+ .rvmrc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ .powenv
22
+ .idea/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :example do
6
- gem 'sinatra'
7
- end
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
- # OmniAuth Samaritan OAuth2 Strategy
2
-
3
- Strategy to authenticate with Samaritan via OAuth2 in OmniAuth.
4
-
5
- #For more information on usage and configuration, visit our [documentation site](http://docs.samaritanministries.org/ruby-oauth/).
6
-
7
- ## License
8
-
9
- Copyright (c) 2014 by Samaritan Ministries International
10
-
11
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ # OmniAuth Samaritan OAuth2 Strategy
2
+ [![Build Status](https://travis-ci.org/samaritanministries/omniauth-samaritan.svg?branch=master)](https://travis-ci.org/samaritanministries/omniauth-samaritan)
3
+
4
+ Strategy to authenticate with Samaritan via OAuth2 in OmniAuth.
5
+
6
+ #For more information on usage and configuration, visit our [documentation site](http://docs.samaritanministries.org/ruby-oauth/).
7
+
8
+ ## License
9
+
10
+ Copyright (c) 2014 by Samaritan Ministries International
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env rake
2
- require File.join('bundler', 'gem_tasks')
3
- require File.join('rspec', 'core', 'rake_task')
4
-
5
- RSpec::Core::RakeTask.new(:spec)
6
-
1
+ #!/usr/bin/env rake
2
+ require File.join('bundler', 'gem_tasks')
3
+ require File.join('rspec', 'core', 'rake_task')
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
7
  task :default => :spec
@@ -1 +1 @@
1
- require File.join('omniauth', 'samaritan')
1
+ require File.join('omniauth', 'samaritan')
@@ -1 +1 @@
1
- require File.join('omniauth', 'strategies', 'samaritan')
1
+ require File.join('omniauth', 'strategies', 'samaritan')
@@ -1,5 +1,5 @@
1
- module OmniAuth
2
- module Samaritan
3
- VERSION = "0.1.2"
4
- end
5
- end
1
+ module OmniAuth
2
+ module Samaritan
3
+ VERSION = "0.1.3"
4
+ end
5
+ end
@@ -1,91 +1,91 @@
1
- require 'omniauth/strategies/oauth2'
2
-
3
- module OmniAuth
4
- module Strategies
5
- class Samaritan < OmniAuth::Strategies::OAuth2
6
-
7
- option :name, 'samaritan'
8
- option :environment
9
-
10
- option :client_options, {}
11
-
12
- option :sandbox_client_options, {
13
- :authorize_url => 'https://sandbox.smchcn.net/asrv/smi/oauth/authorize',
14
- :token_url => 'https://sandbox.smchcn.net/asrv/smi/oauth/token',
15
- :identity_url => 'https://sandbox.smchcn.net/smi/api/identity/mine'}
16
-
17
- option :production_client_options, {
18
- :authorize_url => 'https://accounts.samaritanministries.org/auth/smi/oauth/authorize',
19
- :token_url => 'https://accounts.samaritanministries.org/auth/smi/oauth/token',
20
- :identity_url => 'https://platformapi.samaritanministries.org/smi/api/identity/mine'}
21
-
22
- def client_options
23
- client_options = options.client_options
24
- client_options = options.sandbox_client_options if options.environment == :sandbox
25
- client_options = options.production_client_options if options.environment == :production
26
- client_options
27
- end
28
-
29
- def request_phase
30
- if request.params['access_token']
31
- self.access_token = build_access_token_from_params(request.params)
32
- env['omniauth.auth'] = auth_hash
33
- call_app!
34
- else
35
- super
36
- end
37
- end
38
-
39
- def client
40
- ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(client_options))
41
- end
42
-
43
- def token_params
44
- super.merge({:headers => {'Authorization' => authorization(options.client_id, options.client_secret)}})
45
- end
46
-
47
- def authorization(client_id, client_secret)
48
- 'Basic ' + Base64.encode64(client_id + ':' + client_secret).gsub("\n", '')
49
- end
50
-
51
- uid { raw_info['id'] }
52
-
53
- info do
54
- prune!({
55
- :name => raw_info['nickname'],
56
- :email => raw_info['email_address'],
57
- :member_id => raw_info['member_id'],
58
- :membership_id => raw_info['context'],
59
- :is_approved => raw_info['is_approved'],
60
- :has_claimed_membership => raw_info['has_claimed_membership'],
61
- :is_locked_out => raw_info['is_locked_out']
62
- })
63
- end
64
-
65
- extra do
66
- hash = {}
67
- hash[:raw_info] = raw_info unless skip_info?
68
- prune! hash
69
- end
70
-
71
- def raw_info
72
- identity_endpoint = client_options[:site].to_s.gsub(/\/\z/, '') + client_options[:identity_url].to_s
73
- @raw_info ||= access_token.get(identity_endpoint).parsed
74
- end
75
-
76
- private
77
-
78
- def build_access_token_from_params(params)
79
- ::OAuth2::AccessToken.new(client, params['access_token'])
80
- end
81
-
82
- def prune!(hash)
83
- hash.delete_if do |_, v|
84
- prune!(v) if v.is_a?(Hash)
85
- v.nil? || (v.respond_to?(:empty?) && v.empty?)
86
- end
87
- end
88
-
89
- end
90
- end
91
- end
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Samaritan < OmniAuth::Strategies::OAuth2
6
+
7
+ option :name, 'samaritan'
8
+ option :environment
9
+
10
+ option :client_options, {}
11
+
12
+ option :sandbox_client_options, {
13
+ :authorize_url => 'https://dev-accounts.smchcn.net/Auth/smi/oauth/authorize',
14
+ :token_url => 'https://dev-accounts.smchcn.net/Auth/smi/oauth/token',
15
+ :identity_url => 'https://dev-platformapi.smchcn.net/smi/api/identity/mine'}
16
+
17
+ option :production_client_options, {
18
+ :authorize_url => 'https://accounts.samaritanministries.org/auth/smi/oauth/authorize',
19
+ :token_url => 'https://accounts.samaritanministries.org/auth/smi/oauth/token',
20
+ :identity_url => 'https://platformapi.samaritanministries.org/smi/api/identity/mine'}
21
+
22
+ def client_options
23
+ client_options = options.client_options
24
+ client_options = options.sandbox_client_options if options.environment == :sandbox
25
+ client_options = options.production_client_options if options.environment == :production
26
+ client_options
27
+ end
28
+
29
+ def request_phase
30
+ if request.params['access_token']
31
+ self.access_token = build_access_token_from_params(request.params)
32
+ env['omniauth.auth'] = auth_hash
33
+ call_app!
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ def client
40
+ ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(client_options))
41
+ end
42
+
43
+ def token_params
44
+ super.merge({:headers => {'Authorization' => authorization(options.client_id, options.client_secret)}})
45
+ end
46
+
47
+ def authorization(client_id, client_secret)
48
+ 'Basic ' + Base64.encode64(client_id + ':' + client_secret).gsub("\n", '')
49
+ end
50
+
51
+ uid { raw_info['id'] }
52
+
53
+ info do
54
+ prune!({
55
+ :name => raw_info['nickname'],
56
+ :email => raw_info['email_address'],
57
+ :member_id => raw_info['member_id'],
58
+ :membership_id => raw_info['context'],
59
+ :is_approved => raw_info['is_approved'],
60
+ :has_claimed_membership => raw_info['has_claimed_membership'],
61
+ :is_locked_out => raw_info['is_locked_out']
62
+ })
63
+ end
64
+
65
+ extra do
66
+ hash = {}
67
+ hash[:raw_info] = raw_info unless skip_info?
68
+ prune! hash
69
+ end
70
+
71
+ def raw_info
72
+ identity_endpoint = client_options[:site].to_s.gsub(/\/\z/, '') + client_options[:identity_url].to_s
73
+ @raw_info ||= access_token.get(identity_endpoint).parsed
74
+ end
75
+
76
+ private
77
+
78
+ def build_access_token_from_params(params)
79
+ ::OAuth2::AccessToken.new(client, params['access_token'])
80
+ end
81
+
82
+ def prune!(hash)
83
+ hash.delete_if do |_, v|
84
+ prune!(v) if v.is_a?(Hash)
85
+ v.nil? || (v.respond_to?(:empty?) && v.empty?)
86
+ end
87
+ end
88
+
89
+ end
90
+ end
91
+ end
@@ -1,25 +1,25 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path(File.join('..', 'lib', 'omniauth', 'samaritan', 'version'), __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.add_dependency 'omniauth', '~> 1.0'
6
-
7
- gem.authors = ["Doug Bradbury", "Ben Voss"]
8
- gem.email = ["smi@8thlight.com", "chandlerroth@smchcn.net"]
9
- gem.description = %q{A Samaritan OAuth2 strategy for OmniAuth 1.x.}
10
- gem.summary = %q{A Samaritan OAuth2 strategy for OmniAuth 1.x}
11
- gem.homepage = "http://docs.samaritanministries.org/ruby-oauth/"
12
- gem.licenses = ['MIT']
13
-
14
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
- gem.files = `git ls-files`.split("\n")
16
- gem.test_files = `git ls-files -- {spec}/*`.split("\n")
17
- gem.name = "omniauth-samaritan"
18
- gem.require_paths = ["lib"]
19
- gem.version = OmniAuth::Samaritan::VERSION
20
-
21
- gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.1', '>= 1.1.2'
22
-
23
- gem.add_development_dependency 'rspec', '~> 2.6.0', '>= 2.6.0'
24
- gem.add_development_dependency 'rake', '~> 0'
25
- end
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.join('..', 'lib', 'omniauth', 'samaritan', 'version'), __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'omniauth', '~> 1.0'
6
+
7
+ gem.authors = ["Doug Bradbury", "Ben Voss"]
8
+ gem.email = ["smi@8thlight.com", "chandlerroth@smchcn.net"]
9
+ gem.description = %q{A Samaritan OAuth2 strategy for OmniAuth 1.x.}
10
+ gem.summary = %q{A Samaritan OAuth2 strategy for OmniAuth 1.x}
11
+ gem.homepage = "http://docs.samaritanministries.org/ruby-oauth/"
12
+ gem.licenses = ['MIT']
13
+
14
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
17
+ gem.name = "omniauth-samaritan"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = OmniAuth::Samaritan::VERSION
20
+
21
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.1', '>= 1.1.2'
22
+
23
+ gem.add_development_dependency 'rspec', '~> 2.6.0', '>= 2.6.0'
24
+ gem.add_development_dependency 'rake', '~> 0'
25
+ end
@@ -1,135 +1,135 @@
1
- require 'spec_helper'
2
- require 'omniauth-samaritan'
3
-
4
- describe OmniAuth::Strategies::Samaritan do
5
- let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
6
- let(:app) {
7
- lambda do
8
- [200, {}, ["Hello."]]
9
- end
10
- }
11
-
12
- subject do
13
- OmniAuth::Strategies::Samaritan.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
14
- strategy.stub(:request) {
15
- request
16
- }
17
- end
18
- end
19
-
20
- before do
21
- OmniAuth.config.test_mode = true
22
- end
23
-
24
- after do
25
- OmniAuth.config.test_mode = false
26
- end
27
-
28
- describe '#client_options' do
29
- it 'has correct authorize_url' do
30
- @options = {:environment => :production}
31
- subject.client.options[:authorize_url].should eq('https://accounts.samaritanministries.org/auth/smi/oauth/authorize')
32
- end
33
-
34
- it 'has correct token_url' do
35
- @options = {:environment => :production}
36
- subject.client.options[:token_url].should eq('https://accounts.samaritanministries.org/auth/smi/oauth/token')
37
- end
38
-
39
- describe "overrides" do
40
- it 'should allow overriding the site' do
41
- @options = {:client_options => {'site' => 'https://example.com'}}
42
- subject.client.site.should == 'https://example.com'
43
- end
44
-
45
- it 'should allow overriding the authorize_url' do
46
- @options = {:client_options => {'authorize_url' => 'https://example.com'}}
47
- subject.client.options[:authorize_url].should == 'https://example.com'
48
- end
49
-
50
- it 'should allow overriding the token_url' do
51
- @options = {:client_options => {'token_url' => 'https://example.com'}}
52
- subject.client.options[:token_url].should == 'https://example.com'
53
- end
54
- end
55
- end
56
-
57
- describe '#token_params' do
58
- it 'should include any token params passed in the :token_params option' do
59
- @options = {:token_params => {:foo => 'bar', :baz => 'zip'}}
60
- subject.token_params['foo'].should eq('bar')
61
- subject.token_params['baz'].should eq('zip')
62
- end
63
- end
64
-
65
- describe "#token_options" do
66
- it 'should include top-level options that are marked as :token_options' do
67
- @options = {:token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz', :bad => 'not_included'}
68
- subject.token_params['scope'].should eq('bar')
69
- subject.token_params['foo'].should eq('baz')
70
- subject.token_params['bad'].should eq(nil)
71
- end
72
- end
73
-
74
- describe '#callback_path' do
75
- it 'has the correct callback path' do
76
- subject.callback_path.should eq('/auth/samaritan/callback')
77
- end
78
- end
79
-
80
- describe '#extra' do
81
- let(:client) do
82
- OAuth2::Client.new('abc', 'def') do |builder|
83
- builder.request :url_encoded
84
- builder.adapter :test do |stub|
85
- stub.get('/smi/api/identity/mine') {|env| [200, {'content-type' => 'application/json'}, '{"id": "12345"}']}
86
- end
87
- end
88
- end
89
- let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
90
-
91
- before do
92
- @options = { :environment => :sandbox }
93
- subject.stub(:access_token => access_token)
94
- end
95
-
96
-
97
- describe 'raw_info' do
98
- context 'when skip_info is false' do
99
-
100
- it 'should include raw_info' do
101
- subject.extra[:raw_info].should eq('id' => '12345')
102
- end
103
- end
104
- end
105
-
106
- end
107
-
108
- describe 'populate auth hash urls' do
109
- it 'should populate url map in auth hash if link present in raw_info' do
110
- subject.stub(:raw_info){{"id" => "765b1357-8cb5-4b3e-a4bb-239e3af38399","email_address"=>"gotteo@gmail.com","is_approved"=>true,"is_locked_out"=>false,"sub"=>"765b1357-8cb5-4b3e-a4bb-239e3af38399","member_id"=>"44561","context"=>"14470","has_claimed_membership"=>true,"nickname"=>"Greg Otte"}}
111
- subject.info.should_not have_key(:urls)
112
- subject.info[:name].should == "Greg Otte"
113
- subject.info[:email].should == "gotteo@gmail.com"
114
- subject.info[:is_approved].should == true
115
- subject.info[:has_claimed_membership].should == true
116
- subject.info[:is_locked_out].should == false
117
- subject.info[:member_id].should == "44561"
118
- subject.info[:membership_id].should == "14470"
119
- end
120
-
121
- end
122
-
123
- describe "pre-authorized" do
124
- it "should create an access token" do
125
- subject.stub(:env){ {}}
126
- subject.should_receive(:call_app!)
127
- subject.stub(:raw_info){{"id" => "765b1357-8cb5-4b3e-a4bb-239e3af38399","email_address"=>"gotteo@gmail.com","is_approved"=>true,"is_locked_out"=>false,"sub"=>"765b1357-8cb5-4b3e-a4bb-239e3af38399","member_id"=>"44561","context"=>"14470","has_claimed_membership"=>true,"nickname"=>"Greg Otte"}}
128
- request.params["access_token"] = "1234567890"
129
- subject.request_phase
130
- subject.access_token.should_not be_nil
131
- end
132
-
133
- end
134
-
135
- end
1
+ require 'spec_helper'
2
+ require 'omniauth-samaritan'
3
+
4
+ describe OmniAuth::Strategies::Samaritan do
5
+ let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
6
+ let(:app) {
7
+ lambda do
8
+ [200, {}, ["Hello."]]
9
+ end
10
+ }
11
+
12
+ subject do
13
+ OmniAuth::Strategies::Samaritan.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
14
+ strategy.stub(:request) {
15
+ request
16
+ }
17
+ end
18
+ end
19
+
20
+ before do
21
+ OmniAuth.config.test_mode = true
22
+ end
23
+
24
+ after do
25
+ OmniAuth.config.test_mode = false
26
+ end
27
+
28
+ describe '#client_options' do
29
+ it 'has correct authorize_url' do
30
+ @options = {:environment => :production}
31
+ subject.client.options[:authorize_url].should eq('https://accounts.samaritanministries.org/auth/smi/oauth/authorize')
32
+ end
33
+
34
+ it 'has correct token_url' do
35
+ @options = {:environment => :production}
36
+ subject.client.options[:token_url].should eq('https://accounts.samaritanministries.org/auth/smi/oauth/token')
37
+ end
38
+
39
+ describe "overrides" do
40
+ it 'should allow overriding the site' do
41
+ @options = {:client_options => {'site' => 'https://example.com'}}
42
+ subject.client.site.should == 'https://example.com'
43
+ end
44
+
45
+ it 'should allow overriding the authorize_url' do
46
+ @options = {:client_options => {'authorize_url' => 'https://example.com'}}
47
+ subject.client.options[:authorize_url].should == 'https://example.com'
48
+ end
49
+
50
+ it 'should allow overriding the token_url' do
51
+ @options = {:client_options => {'token_url' => 'https://example.com'}}
52
+ subject.client.options[:token_url].should == 'https://example.com'
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#token_params' do
58
+ it 'should include any token params passed in the :token_params option' do
59
+ @options = {:token_params => {:foo => 'bar', :baz => 'zip'}}
60
+ subject.token_params['foo'].should eq('bar')
61
+ subject.token_params['baz'].should eq('zip')
62
+ end
63
+ end
64
+
65
+ describe "#token_options" do
66
+ it 'should include top-level options that are marked as :token_options' do
67
+ @options = {:token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz', :bad => 'not_included'}
68
+ subject.token_params['scope'].should eq('bar')
69
+ subject.token_params['foo'].should eq('baz')
70
+ subject.token_params['bad'].should eq(nil)
71
+ end
72
+ end
73
+
74
+ describe '#callback_path' do
75
+ it 'has the correct callback path' do
76
+ subject.callback_path.should eq('/auth/samaritan/callback')
77
+ end
78
+ end
79
+
80
+ describe '#extra' do
81
+ let(:client) do
82
+ OAuth2::Client.new('abc', 'def') do |builder|
83
+ builder.request :url_encoded
84
+ builder.adapter :test do |stub|
85
+ stub.get('/smi/api/identity/mine') {|env| [200, {'content-type' => 'application/json'}, '{"id": "12345"}']}
86
+ end
87
+ end
88
+ end
89
+ let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
90
+
91
+ before do
92
+ @options = { :environment => :sandbox }
93
+ subject.stub(:access_token => access_token)
94
+ end
95
+
96
+
97
+ describe 'raw_info' do
98
+ context 'when skip_info is false' do
99
+
100
+ it 'should include raw_info' do
101
+ subject.extra[:raw_info].should eq('id' => '12345')
102
+ end
103
+ end
104
+ end
105
+
106
+ end
107
+
108
+ describe 'populate auth hash urls' do
109
+ it 'should populate url map in auth hash if link present in raw_info' do
110
+ subject.stub(:raw_info){{"id" => "765b1357-8cb5-4b3e-a4bb-239e3af38399","email_address"=>"gotteo@gmail.com","is_approved"=>true,"is_locked_out"=>false,"sub"=>"765b1357-8cb5-4b3e-a4bb-239e3af38399","member_id"=>"44561","context"=>"14470","has_claimed_membership"=>true,"nickname"=>"Greg Otte"}}
111
+ subject.info.should_not have_key(:urls)
112
+ subject.info[:name].should == "Greg Otte"
113
+ subject.info[:email].should == "gotteo@gmail.com"
114
+ subject.info[:is_approved].should == true
115
+ subject.info[:has_claimed_membership].should == true
116
+ subject.info[:is_locked_out].should == false
117
+ subject.info[:member_id].should == "44561"
118
+ subject.info[:membership_id].should == "14470"
119
+ end
120
+
121
+ end
122
+
123
+ describe "pre-authorized" do
124
+ it "should create an access token" do
125
+ subject.stub(:env){ {}}
126
+ subject.should_receive(:call_app!)
127
+ subject.stub(:raw_info){{"id" => "765b1357-8cb5-4b3e-a4bb-239e3af38399","email_address"=>"gotteo@gmail.com","is_approved"=>true,"is_locked_out"=>false,"sub"=>"765b1357-8cb5-4b3e-a4bb-239e3af38399","member_id"=>"44561","context"=>"14470","has_claimed_membership"=>true,"nickname"=>"Greg Otte"}}
128
+ request.params["access_token"] = "1234567890"
129
+ subject.request_phase
130
+ subject.access_token.should_not be_nil
131
+ end
132
+
133
+ end
134
+
135
+ end
@@ -1,2 +1,2 @@
1
- require File.join('bundler', 'setup')
1
+ require File.join('bundler', 'setup')
2
2
  require 'rspec'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-samaritan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Bradbury
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-24 00:00:00.000000000 Z
12
+ date: 2015-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - .gitignore
91
+ - .travis.yml
91
92
  - Gemfile
92
93
  - README.md
93
94
  - Rakefile