omniauth-bunq 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: 54a43ec596604ce0b297e07d08a46061c7fced02
4
+ data.tar.gz: c6923968989fdf21a36fbb607cf1e2c2d2bd9c19
5
+ SHA512:
6
+ metadata.gz: 67a6dc047dbec1df554d7a2d18bbbc92d0ca4657c41a25110d0e704706561a07bbc2d05cd09104976fdfec2b1f42776124ef4a21bdbc98d650f72947bbf3e8e0
7
+ data.tar.gz: c934b168107d7012b132143ef45a1bfa85781f446effee1b4e8e473b9d55caf3c0d04b32b38a0dbeb69293e9ce2619973d6f8b094983582723a694720e996290
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-github.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ gem 'rake'
13
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch('omniauth-rabobank.gemspec')
10
+ end
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # OmniAuth Bunq
2
+
3
+ This is the official OmniAuth strategy for authenticating to Rabobank. To
4
+ use it, you'll need to sign up for an OAuth2 Application ID and Secret
5
+ on the [Bunq Applications Page]().
6
+
7
+ ## Basic Usage
8
+
9
+ ```ruby
10
+ use OmniAuth::Builder do
11
+ provider :bunq, ENV['BUNQ_KEY'], ENV['BUNQ_SECRET']
12
+ end
13
+ ```
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-bunq/version"
2
+ require 'omniauth/strategies/bunq'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Bunq
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,80 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Bunq < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => 'https://api-sandbox.rabobank.nl',
8
+ :authorize_url => 'https://api-sandbox.rabobank.nl/openapi/sandbox/oauth2/authorize',
9
+ :token_url => 'https://api-sandbox.rabobank.nl/openapi/sandbox/oauth2/token'
10
+ }
11
+
12
+ def request_phase
13
+ super
14
+ end
15
+
16
+ def authorize_params
17
+ super.tap do |params|
18
+ %w[scope client_options].each do |v|
19
+ if request.params[v]
20
+ params[v.to_sym] = request.params[v]
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ uid { raw_info['id'].to_s }
27
+
28
+ info do
29
+ {
30
+ 'nickname' => raw_info['login'],
31
+ 'email' => email,
32
+ 'name' => raw_info['name'],
33
+ 'image' => raw_info['avatar_url'],
34
+ 'urls' => {
35
+ 'GitHub' => raw_info['html_url'],
36
+ 'Blog' => raw_info['blog'],
37
+ },
38
+ }
39
+ end
40
+
41
+ extra do
42
+ {:raw_info => raw_info, :all_emails => emails}
43
+ end
44
+
45
+ def raw_info
46
+ access_token.options[:mode] = :query
47
+ @raw_info ||= access_token.get('user').parsed
48
+ end
49
+
50
+ def email
51
+ (email_access_allowed?) ? primary_email : raw_info['email']
52
+ end
53
+
54
+ def primary_email
55
+ primary = emails.find{ |i| i['primary'] && i['verified'] }
56
+ primary && primary['email'] || nil
57
+ end
58
+
59
+ # The new /user/emails API - http://developer.github.com/v3/users/emails/#future-response
60
+ def emails
61
+ return [] unless email_access_allowed?
62
+ access_token.options[:mode] = :query
63
+ @emails ||= access_token.get('user/emails', :headers => { 'Accept' => 'application/vnd.github.v3' }).parsed
64
+ end
65
+
66
+ def email_access_allowed?
67
+ return false unless options['scope']
68
+ email_scopes = ['user', 'user:email']
69
+ scopes = options['scope'].split(',')
70
+ (scopes & email_scopes).any?
71
+ end
72
+
73
+ def callback_url
74
+ full_host + script_name + callback_path
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ OmniAuth.config.add_camelization 'bunq', 'Bunq'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-bunq/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dunya Kirkali"]
6
+ gem.email = ["dunyakirkali@gmail.com"]
7
+ gem.description = %q{Official OmniAuth strategy for Bunq.}
8
+ gem.summary = %q{Official OmniAuth strategy for Bunq.}
9
+ gem.homepage = "https://github.com/ahtung/omniauth-bunq"
10
+ gem.license = "MIT"
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.name = "omniauth-bunq"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = OmniAuth::Bunq::VERSION
18
+
19
+ gem.add_dependency 'omniauth', '~> 1.5'
20
+ gem.add_dependency 'omniauth-oauth2', '>= 1.4.0', '< 2.0'
21
+ gem.add_development_dependency 'rspec', '~> 3.5'
22
+ gem.add_development_dependency 'rack-test'
23
+ gem.add_development_dependency 'simplecov'
24
+ gem.add_development_dependency 'webmock'
25
+ end
@@ -0,0 +1,161 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Bunq do
4
+ let(:access_token) { instance_double('AccessToken', :options => {}) }
5
+ let(:parsed_response) { instance_double('ParsedResponse') }
6
+ let(:response) { instance_double('Response', :parsed => parsed_response) }
7
+
8
+ let(:enterprise_site) { 'https://some.other.site.com/api/v3' }
9
+ let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
10
+ let(:enterprise_token_url) { 'https://some.other.site.com/login/oauth/access_token' }
11
+ let(:enterprise) do
12
+ OmniAuth::Strategies::Bunq.new('BUNQ_KEY', 'BUNQ_SECRET',
13
+ {
14
+ :client_options => {
15
+ :site => enterprise_site,
16
+ :authorize_url => enterprise_authorize_url,
17
+ :token_url => enterprise_token_url
18
+ }
19
+ }
20
+ )
21
+ end
22
+
23
+ subject do
24
+ OmniAuth::Strategies::Bunq.new({})
25
+ end
26
+
27
+ before(:each) do
28
+ allow(subject).to receive(:access_token).and_return(access_token)
29
+ end
30
+
31
+ context 'client options' do
32
+ it 'should have correct site' do
33
+ expect(subject.options.client_options.site).to eq('https://api-sandbox.rabobank.nl')
34
+ end
35
+
36
+ it 'should have correct authorize url' do
37
+ expect(subject.options.client_options.authorize_url).to eq('https://api-sandbox.rabobank.nl/openapi/sandbox/oauth2/authorize')
38
+ end
39
+
40
+ it 'should have correct token url' do
41
+ expect(subject.options.client_options.token_url).to eq('https://api-sandbox.rabobank.nl/openapi/sandbox/oauth2/token')
42
+ end
43
+
44
+ describe 'should be overrideable' do
45
+ it 'for site' do
46
+ expect(enterprise.options.client_options.site).to eq(enterprise_site)
47
+ end
48
+
49
+ it 'for authorize url' do
50
+ expect(enterprise.options.client_options.authorize_url).to eq(enterprise_authorize_url)
51
+ end
52
+
53
+ it 'for token url' do
54
+ expect(enterprise.options.client_options.token_url).to eq(enterprise_token_url)
55
+ end
56
+ end
57
+ end
58
+
59
+ context '#email_access_allowed?' do
60
+ it 'should not allow email if scope is nil' do
61
+ expect(subject.options['scope']).to be_nil
62
+ expect(subject).to_not be_email_access_allowed
63
+ end
64
+
65
+ it 'should allow email if scope is user' do
66
+ subject.options['scope'] = 'user'
67
+ expect(subject).to be_email_access_allowed
68
+ end
69
+
70
+ it 'should allow email if scope is a bunch of stuff including user' do
71
+ subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist'
72
+ expect(subject).to be_email_access_allowed
73
+ end
74
+
75
+ it 'should not allow email if scope does not grant email access' do
76
+ subject.options['scope'] = 'repo,user:follow'
77
+ expect(subject).to_not be_email_access_allowed
78
+ end
79
+
80
+ it 'should assume email access not allowed if scope is something currently not documented' do
81
+ subject.options['scope'] = 'currently_not_documented'
82
+ expect(subject).to_not be_email_access_allowed
83
+ end
84
+ end
85
+
86
+ context '#email' do
87
+ it 'should return email from raw_info if available' do
88
+ allow(subject).to receive(:raw_info).and_return({ 'email' => 'you@example.com' })
89
+ expect(subject.email).to eq('you@example.com')
90
+ end
91
+
92
+ it 'should return nil if there is no raw_info and email access is not allowed' do
93
+ allow(subject).to receive(:raw_info).and_return({})
94
+ expect(subject.email).to be_nil
95
+ end
96
+
97
+ it 'should not return the primary email if there is no raw_info and email access is allowed' do
98
+ emails = [
99
+ { 'email' => 'secondary@example.com', 'primary' => false },
100
+ { 'email' => 'primary@example.com', 'primary' => true }
101
+ ]
102
+ allow(subject).to receive(:raw_info).and_return({})
103
+ subject.options['scope'] = 'user'
104
+ allow(subject).to receive(:emails).and_return(emails)
105
+ expect(subject.email).to be_nil
106
+ end
107
+
108
+ it 'should not return the first email if there is no raw_info and email access is allowed' do
109
+ emails = [
110
+ { 'email' => 'first@example.com', 'primary' => false },
111
+ { 'email' => 'second@example.com', 'primary' => false }
112
+ ]
113
+ allow(subject).to receive(:raw_info).and_return({})
114
+ subject.options['scope'] = 'user'
115
+ allow(subject).to receive(:emails).and_return(emails)
116
+ expect(subject.email).to be_nil
117
+ end
118
+ end
119
+
120
+ context '#raw_info' do
121
+ it 'should use relative paths' do
122
+ expect(access_token).to receive(:get).with('user').and_return(response)
123
+ expect(subject.raw_info).to eq(parsed_response)
124
+ end
125
+ end
126
+
127
+ context '#emails' do
128
+ it 'should use relative paths' do
129
+ expect(access_token).to receive(:get).with('user/emails', :headers => {
130
+ 'Accept' => 'application/vnd.github.v3'
131
+ }).and_return(response)
132
+
133
+ subject.options['scope'] = 'user'
134
+ expect(subject.emails).to eq(parsed_response)
135
+ end
136
+ end
137
+
138
+ context '#info.email' do
139
+ it 'should use any available email' do
140
+ allow(subject).to receive(:raw_info).and_return({})
141
+ allow(subject).to receive(:email).and_return('you@example.com')
142
+ expect(subject.info['email']).to eq('you@example.com')
143
+ end
144
+ end
145
+
146
+ context '#info.urls' do
147
+ it 'should use html_url from raw_info' do
148
+ allow(subject).to receive(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' })
149
+ expect(subject.info['urls']['GitHub']).to eq('http://enterprise/me')
150
+ end
151
+ end
152
+
153
+ describe '#callback_url' do
154
+ it 'is a combination of host, script name, and callback path' do
155
+ allow(subject).to receive(:full_host).and_return('https://example.com')
156
+ allow(subject).to receive(:script_name).and_return('/sub_uri')
157
+
158
+ expect(subject.callback_url).to eq('https://example.com/sub_uri/auth/bunq/callback')
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-bunq'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-bunq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dunya Kirkali
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-22 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.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.4.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.5'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.5'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rack-test
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: simplecov
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: webmock
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: Official OmniAuth strategy for Bunq.
104
+ email:
105
+ - dunyakirkali@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - ".rspec"
112
+ - Gemfile
113
+ - Guardfile
114
+ - README.md
115
+ - Rakefile
116
+ - lib/omniauth-bunq.rb
117
+ - lib/omniauth-bunq/version.rb
118
+ - lib/omniauth/strategies/bunq.rb
119
+ - omniauth-bunq.gemspec
120
+ - spec/omniauth/strategies/bunq_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: https://github.com/ahtung/omniauth-bunq
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Official OmniAuth strategy for Bunq.
146
+ test_files:
147
+ - spec/omniauth/strategies/bunq_spec.rb
148
+ - spec/spec_helper.rb