omniauth-healpay 0.0.1

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.
@@ -0,0 +1,3 @@
1
+ .bundle
2
+ Gemfile.lock
3
+ *~
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1 @@
1
+ require 'omniauth/healpay'
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/healpay'
@@ -0,0 +1,48 @@
1
+ #require 'omniauth/oauth'
2
+ require 'omniauth/strategies/oauth2'
3
+ require 'multi_json'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Healpay < OmniAuth::Strategies::OAuth2
8
+ #def initialize(app, api_key = nil, secret_key = nil, options = {}, &block)
9
+ # client_options = {
10
+ # :site => "http://gate.healpay.com",
11
+ # :authorize_url => "http://gate.healpay.com/oauth/healpay/authorize",
12
+ # :access_token_url => "http://gate.healpay.com/oauth/healpay/access_token"
13
+ # }
14
+ # super(app, :healpay_id, api_key, secret_key, client_options, &block)
15
+ #end
16
+
17
+ option :client_options, {
18
+ :site => "http://gate.healpay.com",
19
+ :authorize_url => "http://gate.healpay.com/oauth/healpay/authorize",
20
+ :token_url => "http://gate.healpay.com/oauth/healpay/access_token"
21
+ }
22
+
23
+ def request_phase
24
+ super
25
+ end
26
+
27
+ uid { raw_info['id'] }
28
+
29
+ info do
30
+ {
31
+ 'first_name' => raw_info['first_name'],
32
+ 'last_name' => raw_info['last_name'],
33
+ 'email' => raw_info['email']
34
+ }
35
+ end
36
+
37
+ extra do
38
+ {:raw_info => raw_info}
39
+ end
40
+
41
+ def raw_info
42
+ access_token.options[:mode] = :query
43
+ @raw_info ||= access_token.get('/user').parsed
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'omniauth-healpay'
6
+ s.version = '0.0.1'
7
+ s.authors = ['Lance Carlson']
8
+ s.email = ['lcarlson@healpay.com']
9
+ s.summary = 'Healpay strategy for OmniAuth'
10
+ s.homepage = 'https://github.com/healpay/omniauth-healpay'
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15
+ s.require_paths = ['lib']
16
+
17
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.0.0'
18
+
19
+ s.add_development_dependency 'rspec', '~> 2.7.0'
20
+ s.add_development_dependency 'rake'
21
+ end
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-healpay'
3
+
4
+ describe OmniAuth::Strategies::Healpay do
5
+ before :each do
6
+ @request = double('Request')
7
+ @request.stub(:params) { {} }
8
+ end
9
+
10
+ subject do
11
+ OmniAuth::Strategies::Healpay.new(nil, @options || {}).tap do |strategy|
12
+ strategy.stub(:request) { @request }
13
+ end
14
+ end
15
+
16
+ it_should_behave_like 'an oauth2 strategy'
17
+
18
+ describe '#client' do
19
+ it 'has correct Healpay site' do
20
+ subject.client.site.should eq('https://gate.healpay.com')
21
+ end
22
+
23
+ it 'has correct authorize url' do
24
+ subject.client.options[:authorize_url].should eq('https://gate.healpay.com/oauth/healpay/authorize')
25
+ end
26
+
27
+ it 'has correct token url' do
28
+ subject.client.options[:token_url].should eq('https://gate.healpay.com/oauth/healpay/access_token')
29
+ end
30
+ end
31
+
32
+ describe '#callback_url' do
33
+ it " callback_url from request" do
34
+ url_base = 'http://auth.request.com'
35
+ @request.stub(:url){ url_base + "/page/path" }
36
+ subject.stub(:script_name) { "" } # to not depend from Rack env
37
+ subject.callback_url.should == url_base + "/auth/healpay/callback"
38
+ end
39
+ end
40
+
41
+ describe '#uid' do
42
+ before :each do
43
+ subject.stub(:raw_info) { { 'id' => '123' } }
44
+ end
45
+
46
+ it 'returns the id from raw_info' do
47
+ subject.uid.should eq('123')
48
+ end
49
+ end
50
+
51
+ describe '#info' do
52
+ before :each do
53
+ @raw_info ||= { 'name' => 'Fred Smith' }
54
+ subject.stub(:raw_info) { @raw_info }
55
+ end
56
+
57
+ context 'when data is present in raw info' do
58
+ it 'returns the email' do
59
+ @raw_info['email'] = 'fred@smith.com'
60
+ subject.info['email'].should eq('fred@smith.com')
61
+ end
62
+
63
+ it 'returns the first name' do
64
+ @raw_info['first_name'] = 'Fred'
65
+ subject.info['first_name'].should eq('Fred')
66
+ end
67
+
68
+ it 'returns the last name' do
69
+ @raw_info['last_name'] = 'Smith'
70
+ subject.info['last_name'].should eq('Smith')
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#raw_info' do
76
+ before :each do
77
+ @access_token = double('OAuth2::AccessToken')
78
+ subject.stub(:access_token) { @access_token }
79
+ end
80
+ end
81
+
82
+ describe '#credentials' do
83
+ before :each do
84
+ @access_token = double('OAuth2::AccessToken')
85
+ @access_token.stub(:token)
86
+ @access_token.stub(:expires?)
87
+ @access_token.stub(:expires_at)
88
+ @access_token.stub(:refresh_token)
89
+ subject.stub(:access_token) { @access_token }
90
+ end
91
+
92
+ it 'returns a Hash' do
93
+ subject.credentials.should be_a(Hash)
94
+ end
95
+
96
+ it 'returns the token' do
97
+ @access_token.stub(:token) { '123' }
98
+ subject.credentials['token'].should eq('123')
99
+ end
100
+
101
+ it 'returns the expiry status' do
102
+ @access_token.stub(:expires?) { true }
103
+ subject.credentials['expires'].should eq(true)
104
+
105
+ @access_token.stub(:expires?) { false }
106
+ subject.credentials['expires'].should eq(false)
107
+ end
108
+
109
+ it 'returns the refresh token and expiry time when expiring' do
110
+ ten_mins_from_now = (Time.now + 600).to_i
111
+ @access_token.stub(:expires?) { true }
112
+ @access_token.stub(:refresh_token) { '321' }
113
+ @access_token.stub(:expires_at) { ten_mins_from_now }
114
+ subject.credentials['refresh_token'].should eq('321')
115
+ subject.credentials['expires_at'].should eq(ten_mins_from_now)
116
+ end
117
+
118
+ it 'does not return the refresh token when it is nil and expiring' do
119
+ @access_token.stub(:expires?) { true }
120
+ @access_token.stub(:refresh_token) { nil }
121
+ subject.credentials['refresh_token'].should be_nil
122
+ subject.credentials.should_not have_key('refresh_token')
123
+ end
124
+
125
+ it 'does not return the refresh token when not expiring' do
126
+ @access_token.stub(:expires?) { false }
127
+ @access_token.stub(:refresh_token) { 'XXX' }
128
+ subject.credentials['refresh_token'].should be_nil
129
+ subject.credentials.should_not have_key('refresh_token')
130
+ end
131
+ end
132
+
133
+ describe '#extra' do
134
+ before :each do
135
+ @raw_info = { 'name' => 'Fred Smith' }
136
+ subject.stub(:raw_info) { @raw_info }
137
+ end
138
+
139
+ it 'returns a Hash' do
140
+ subject.extra.should be_a(Hash)
141
+ end
142
+
143
+ it 'contains raw info' do
144
+ subject.extra.should eq({ :raw_info => @raw_info })
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,37 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ shared_examples 'an oauth2 strategy' do
3
+ describe '#client' do
4
+ it 'should be initialized with symbolized client_options' do
5
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
6
+ subject.client.options[:authorize_url].should == 'https://example.com'
7
+ end
8
+ end
9
+
10
+ describe '#authorize_params' do
11
+ it 'should include any authorize params passed in the :authorize_params option' do
12
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
13
+ subject.authorize_params['foo'].should eq('bar')
14
+ subject.authorize_params['baz'].should eq('zip')
15
+ end
16
+
17
+ it 'should include top-level options that are marked as :authorize_options' do
18
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ subject.authorize_params['scope'].should eq('bar')
20
+ subject.authorize_params['foo'].should eq('baz')
21
+ end
22
+ end
23
+
24
+ describe '#token_params' do
25
+ it 'should include any authorize params passed in the :authorize_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ subject.token_params['foo'].should eq('bar')
28
+ subject.token_params['baz'].should eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :authorize_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ subject.token_params['scope'].should eq('bar')
34
+ subject.token_params['foo'].should eq('baz')
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-healpay
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Lance Carlson
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-12-09 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: omniauth-oauth2
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 2
45
+ - 7
46
+ - 0
47
+ version: 2.7.0
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rake
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description:
64
+ email:
65
+ - lcarlson@healpay.com
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - Gemfile
75
+ - Rakefile
76
+ - lib/omniauth-healpay.rb
77
+ - lib/omniauth/healpay.rb
78
+ - lib/omniauth/strategies/healpay.rb
79
+ - omniauth-healpay.gemspec
80
+ - spec/omniauth/strategies/healpay_spec.rb
81
+ - spec/spec_helper.rb
82
+ - spec/support/shared_examples.rb
83
+ has_rdoc: true
84
+ homepage: https://github.com/healpay/omniauth-healpay
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Healpay strategy for OmniAuth
115
+ test_files:
116
+ - spec/omniauth/strategies/healpay_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/support/shared_examples.rb