omniauth-swedbank 0.0.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +6 -0
- data/LICENSE.txt +1 -1
- data/README.md +52 -3
- data/lib/omniauth-swedbank.rb +4 -1
- data/lib/omniauth/locales/omniauth.en.yml +5 -0
- data/lib/omniauth/locales/omniauth.lv.yml +5 -0
- data/lib/omniauth/strategies/swedbank.rb +60 -60
- data/lib/omniauth/swedbank.rb +1 -1
- data/lib/omniauth/swedbank/version.rb +1 -1
- data/omniauth-swedbank.gemspec +10 -6
- data/{certs → spec/certs}/request.private.pem +0 -0
- data/{certs → spec/certs}/response.public.pem +0 -0
- data/spec/omniauth/strategies/swedbank_spec.rb +111 -114
- data/spec/spec_helper.rb +4 -2
- metadata +45 -34
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0771558c29f141a92ba04dac605eca8dcc169009
|
4
|
+
data.tar.gz: 4617272b07b93f44b1d9e8526871206e91dfba63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e01dac01185b8e267efded3598fd5f69b8d2dcaa3e6a30847434b5c7a490986f5f3c3684985731914968838cd90b0c7852a1e11002cea2693ed40298b93467c3
|
7
|
+
data.tar.gz: 1008eb879420bde49410875e903dd0d801099c646ebfc4754974937e0923edb6aafb7b80ca43a9ecc9304a08b301e5fe856b0c08c5516771c8ef0ed2967aab66
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
-
# Omniauth
|
1
|
+
# Omniauth Swedbank
|
2
2
|
|
3
|
-
|
3
|
+
Omniauth strategy for using Swedbank as an authentication service provider.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/omniauth-swedbank.png)](http://badge.fury.io/rb/omniauth-swedbank)
|
6
|
+
[![Build Status](https://travis-ci.org/mak-it/omniauth-swedbank.svg?branch=master)](https://travis-ci.org/mak-it/omniauth-swedbank)
|
7
|
+
|
8
|
+
Supported Ruby versions: 2.2+
|
9
|
+
|
10
|
+
## Related projects
|
11
|
+
|
12
|
+
- [omniauth-citadele](https://github.com/mak-it/omniauth-citadele) - strategy for authenticating with Citadele
|
13
|
+
- [omniauth-dnb](https://github.com/mak-it/omniauth-dnb) - strategy for authenticating with DNB
|
14
|
+
- [omniauth-nordea](https://github.com/mak-it/omniauth-nordea) - strategy for authenticating with Nordea
|
15
|
+
- [omniauth-seb-elink](https://github.com/mak-it/omniauth-seb-elink) - strategy for authenticating with SEB
|
4
16
|
|
5
17
|
## Installation
|
6
18
|
|
@@ -18,7 +30,44 @@ Or install it yourself as:
|
|
18
30
|
|
19
31
|
## Usage
|
20
32
|
|
21
|
-
|
33
|
+
Here's a quick example, adding the middleware to a Rails app
|
34
|
+
in `config/initializers/omniauth.rb`:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
38
|
+
provider :swedbank,
|
39
|
+
File.read("path/to/private.key"),
|
40
|
+
File.read("path/to/bank.crt"),
|
41
|
+
ENV['SWEDBANK_SND_ID'],
|
42
|
+
ENV['SWEDBANK_REC_ID']
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Auth Hash
|
47
|
+
|
48
|
+
Here's an example Auth Hash available in `request.env['omniauth.auth']`:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
{
|
52
|
+
provider: 'swedbank',
|
53
|
+
uid: '374042-80367',
|
54
|
+
info: {
|
55
|
+
full_name: 'ARNIS RAITUMS'
|
56
|
+
},
|
57
|
+
extra: {
|
58
|
+
raw_info: {
|
59
|
+
VK_SERVICE: '3003',
|
60
|
+
VK_VERSION: '008',
|
61
|
+
VK_SND_ID: 'HP',
|
62
|
+
VK_REC_ID: 'MPLMT',
|
63
|
+
VK_NONCE: '20170425114529204413',
|
64
|
+
VK_INFO: 'ISIK:090482-12549;NIMI:DACE ĀBOLA',
|
65
|
+
VK_MAC: 'qrEMRf6YV...',
|
66
|
+
VK_ENCODING: 'UTF-8
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
```
|
22
71
|
|
23
72
|
## Contributing
|
24
73
|
|
data/lib/omniauth-swedbank.rb
CHANGED
@@ -4,126 +4,126 @@ require 'base64'
|
|
4
4
|
module OmniAuth
|
5
5
|
module Strategies
|
6
6
|
class Swedbank
|
7
|
-
# TODO add support for overriding the VK_LANG parameter
|
8
|
-
# TODO i18n for all texts
|
9
|
-
|
10
7
|
include OmniAuth::Strategy
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
# Padding is important when generating the VK_MAC value
|
9
|
+
AUTH_SERVICE = '4002'
|
10
|
+
AUTH_VERSION = '008'
|
15
11
|
|
16
|
-
args [:
|
12
|
+
args [:private_key, :public_key, :snd_id, :rec_id]
|
17
13
|
|
18
|
-
option :
|
19
|
-
option :
|
14
|
+
option :private_key, nil
|
15
|
+
option :public_key, nil
|
20
16
|
option :snd_id, nil
|
21
17
|
option :rec_id, nil
|
22
18
|
|
23
|
-
option :name,
|
24
|
-
option :site,
|
25
|
-
|
26
|
-
def callback_url
|
27
|
-
full_host + script_name + callback_path
|
28
|
-
end
|
19
|
+
option :name, 'swedbank'
|
20
|
+
option :site, 'https://www.swedbank.lv/banklink'
|
29
21
|
|
30
|
-
def
|
31
|
-
return @
|
32
|
-
@
|
22
|
+
def stamp
|
23
|
+
return @stamp if @stamp
|
24
|
+
@stamp = Time.now.strftime('%Y%m%d%H%M%S') + SecureRandom.random_number(999999).to_s.rjust(6, '0')
|
33
25
|
end
|
34
26
|
|
35
|
-
def
|
36
|
-
|
27
|
+
def prepend_length(value)
|
28
|
+
# prepend length to string in 0xx format
|
29
|
+
[ value.to_s.length.to_s.rjust(3, '0'), value.dup.to_s.force_encoding('ascii')].join
|
37
30
|
end
|
38
31
|
|
39
32
|
def signature_input
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
33
|
+
[
|
34
|
+
AUTH_SERVICE, # VK_SERVICE
|
35
|
+
AUTH_VERSION, # VK_VERSION
|
36
|
+
options.snd_id, # VK_SND_ID
|
37
|
+
options.rec_id, # VK_REC_ID
|
38
|
+
stamp, # VK_NONCE
|
39
|
+
callback_url # VK_RETURN
|
40
|
+
].map{|v| prepend_length(v)}.join
|
46
41
|
end
|
47
42
|
|
48
|
-
def signature
|
43
|
+
def signature(priv_key)
|
49
44
|
Base64.encode64(priv_key.sign(OpenSSL::Digest::SHA1.new, signature_input))
|
50
45
|
end
|
51
46
|
|
52
47
|
uid do
|
53
|
-
request.params[
|
48
|
+
request.params['VK_INFO'].match(/ISIK:(\d{6}\-\d{5})/)[1]
|
54
49
|
end
|
55
50
|
|
56
51
|
info do
|
57
52
|
{
|
58
|
-
:
|
53
|
+
full_name: request.params['VK_INFO'].match(/NIMI:(.+)/)[1]
|
59
54
|
}
|
60
55
|
end
|
61
56
|
|
57
|
+
extra do
|
58
|
+
{ raw_info: request.params }
|
59
|
+
end
|
60
|
+
|
62
61
|
def callback_phase
|
63
62
|
begin
|
64
|
-
pub_key = OpenSSL::X509::Certificate.new(
|
63
|
+
pub_key = OpenSSL::X509::Certificate.new(options.public_key).public_key
|
65
64
|
rescue => e
|
66
65
|
return fail!(:public_key_load_err, e)
|
67
66
|
end
|
68
67
|
|
69
|
-
if request.params[
|
68
|
+
if request.params['VK_SERVICE'] != '3003'
|
70
69
|
return fail!(:unsupported_response_service_err)
|
71
70
|
end
|
72
71
|
|
73
|
-
if request.params[
|
72
|
+
if request.params['VK_VERSION'] != '008'
|
74
73
|
return fail!(:unsupported_response_version_err)
|
75
74
|
end
|
76
75
|
|
77
|
-
if request.params[
|
76
|
+
if request.params['VK_ENCODING'] != 'UTF-8'
|
78
77
|
return fail!(:unsupported_response_encoding_err)
|
79
78
|
end
|
80
79
|
|
81
|
-
sig_str =
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
sig_str = [
|
81
|
+
request.params['VK_SERVICE'],
|
82
|
+
request.params['VK_VERSION'],
|
83
|
+
request.params['VK_SND_ID'],
|
84
|
+
request.params['VK_REC_ID'],
|
85
|
+
request.params['VK_NONCE'],
|
86
|
+
request.params['VK_INFO']
|
87
|
+
].map{|v| prepend_length(v)}.join
|
87
88
|
|
88
|
-
raw_signature = Base64.decode64(request.params[
|
89
|
+
raw_signature = Base64.decode64(request.params['VK_MAC'])
|
89
90
|
|
90
91
|
if !pub_key.verify(OpenSSL::Digest::SHA1.new, raw_signature, sig_str)
|
91
92
|
return fail!(:invalid_response_signature_err)
|
92
93
|
end
|
93
94
|
|
94
95
|
super
|
95
|
-
rescue Exception => e
|
96
|
-
fail!(:unknown_callback_err, e)
|
97
96
|
end
|
98
97
|
|
99
98
|
def request_phase
|
100
99
|
begin
|
101
|
-
priv_key = OpenSSL::PKey::RSA.new(
|
100
|
+
priv_key = OpenSSL::PKey::RSA.new(options.private_key)
|
102
101
|
rescue => e
|
103
102
|
return fail!(:private_key_load_err, e)
|
104
103
|
end
|
105
104
|
|
106
|
-
OmniAuth.
|
107
|
-
form = OmniAuth::Form.new(:title => "Please wait ...", :url => options.site)
|
105
|
+
form = OmniAuth::Form.new(:title => I18n.t('omniauth.swedbank.please_wait'), :url => options.site)
|
108
106
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
107
|
+
{
|
108
|
+
'VK_SERVICE' => AUTH_SERVICE,
|
109
|
+
'VK_VERSION' => AUTH_VERSION,
|
110
|
+
'VK_SND_ID' => options.snd_id,
|
111
|
+
'VK_REC_ID' => options.rec_id,
|
112
|
+
'VK_NONCE' => stamp,
|
113
|
+
'VK_RETURN' => callback_url,
|
114
|
+
'VK_MAC' => signature(priv_key),
|
115
|
+
'VK_LANG' => 'LAT',
|
116
|
+
'VK_ENCODING' => 'UTF-8'
|
117
|
+
}.each do |name, val|
|
118
|
+
form.html "<input type=\"hidden\" name=\"#{name}\" value=\"#{val}\" />"
|
119
|
+
end
|
117
120
|
|
118
|
-
form.button
|
121
|
+
form.button I18n.t('omniauth.swedbank.click_here_if_not_redirected')
|
119
122
|
|
120
|
-
form.instance_variable_set(
|
121
|
-
form.to_html.gsub(
|
122
|
-
#puts form.to_html
|
123
|
+
form.instance_variable_set('@html',
|
124
|
+
form.to_html.gsub('</form>', '</form><script type="text/javascript">document.forms[0].submit();</script>'))
|
123
125
|
form.to_response
|
124
|
-
rescue Exception => e
|
125
|
-
fail!(:unknown_request_err, e)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
end
|
129
|
-
end
|
129
|
+
end
|
data/lib/omniauth/swedbank.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'omniauth/swedbank/version'
|
2
|
-
require 'omniauth/strategies/swedbank'
|
2
|
+
require 'omniauth/strategies/swedbank'
|
data/omniauth-swedbank.gemspec
CHANGED
@@ -4,21 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'omniauth/swedbank/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'omniauth-swedbank'
|
8
8
|
spec.version = Omniauth::Swedbank::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['MAK IT', 'Jānis Kiršteins', 'Kristaps Ērglis']
|
10
|
+
spec.email = ['admin@makit.lv', 'janis@montadigital.com', 'kristaps.erglis@gmail.com' ]
|
11
11
|
spec.description = %q{OmniAuth strategy for Swedbank Banklink}
|
12
12
|
spec.summary = %q{OmniAuth strategy for Swedbank Banklink}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/mak-it/omniauth-swedbank'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.2.2'
|
20
22
|
|
21
23
|
spec.add_runtime_dependency 'omniauth', '~> 1.0'
|
24
|
+
spec.add_runtime_dependency "i18n"
|
25
|
+
|
22
26
|
spec.add_development_dependency 'rack-test'
|
23
27
|
spec.add_development_dependency 'rspec', '~> 2.7'
|
24
28
|
spec.add_development_dependency "bundler", "~> 1.3"
|
File without changes
|
File without changes
|
@@ -2,38 +2,36 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe OmniAuth::Strategies::Swedbank do
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
PRIVATE_KEY = File.read(File.join(RSpec.configuration.cert_folder, 'request.private.pem'))
|
6
|
+
PUBLIC_KEY = File.read(File.join(RSpec.configuration.cert_folder, 'response.public.pem'))
|
7
7
|
|
8
8
|
let(:app){ Rack::Builder.new do |b|
|
9
|
-
b.use Rack::Session::Cookie, {:
|
10
|
-
b.use(OmniAuth::Strategies::Swedbank,
|
9
|
+
b.use Rack::Session::Cookie, {secret: 'abc123'}
|
10
|
+
b.use(OmniAuth::Strategies::Swedbank, PRIVATE_KEY, PUBLIC_KEY, 'MY_SND_ID', 'MY_REC_ID')
|
11
11
|
b.run lambda{|env| [404, {}, ['Not Found']]}
|
12
12
|
end.to_app }
|
13
13
|
|
14
|
-
let(:private_key) { OpenSSL::PKey::RSA.new(File.read(PRIVATE_KEY_FILE)) }
|
15
|
-
let(:public_key) { OpenSSL::PKey::RSA.new(File.read(PUBLIC_KEY_FILE)) }
|
16
14
|
let(:last_response_nonce) { last_response.body.match(/name="VK_NONCE" value="([^"]*)"/)[1] }
|
17
15
|
let(:last_response_mac) { last_response.body.match(/name="VK_MAC" value="([^"]*)"/)[1] }
|
18
16
|
|
19
|
-
context
|
17
|
+
context 'request phase' do
|
20
18
|
EXPECTED_VALUES = {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
'VK_SERVICE' => '4002',
|
20
|
+
'VK_VERSION' => '008',
|
21
|
+
'VK_SND_ID' => 'MY_SND_ID',
|
22
|
+
'VK_REC_ID' => 'MY_REC_ID',
|
23
|
+
'VK_RETURN' => 'http://example.org/auth/swedbank/callback'
|
26
24
|
}
|
27
25
|
|
28
26
|
before(:each){ get '/auth/swedbank' }
|
29
27
|
|
30
|
-
it
|
28
|
+
it 'displays a single form' do
|
31
29
|
expect(last_response.status).to eq(200)
|
32
30
|
expect(last_response.body.scan('<form').size).to eq(1)
|
33
31
|
end
|
34
32
|
|
35
|
-
it
|
36
|
-
expect(last_response.body).to be_include(
|
33
|
+
it 'has JavaScript code to submit the form after it is created' do
|
34
|
+
expect(last_response.body).to be_include('</form><script type="text/javascript">document.forms[0].submit();</script>')
|
37
35
|
end
|
38
36
|
|
39
37
|
EXPECTED_VALUES.each_pair do |k,v|
|
@@ -43,166 +41,165 @@ describe OmniAuth::Strategies::Swedbank do
|
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
|
-
it
|
47
|
-
expect(last_response_nonce.bytesize).to eq(
|
44
|
+
it 'has a 50 byte long nonce field value' do
|
45
|
+
expect(last_response_nonce.bytesize).to eq(20)
|
48
46
|
end
|
49
47
|
|
50
|
-
it
|
48
|
+
it 'has a correct VK_MAC signature' do
|
51
49
|
sig_str =
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
"
|
57
|
-
"041#{EXPECTED_VALUES[
|
58
|
-
|
50
|
+
'0044002' + # VK_SERVICE
|
51
|
+
'003008' + # VK_VERSION
|
52
|
+
'009MY_SND_ID' + # VK_SND_ID
|
53
|
+
'009MY_REC_ID' + # VK_REC_ID
|
54
|
+
"020#{last_response_nonce}" + # VK_NONCE
|
55
|
+
"041#{EXPECTED_VALUES['VK_RETURN']}" # V_RETURN
|
56
|
+
|
57
|
+
private_key = OpenSSL::PKey::RSA.new(PRIVATE_KEY)
|
59
58
|
expected_mac = Base64.encode64(private_key.sign(OpenSSL::Digest::SHA1.new, sig_str))
|
60
59
|
expect(last_response_mac).to eq(expected_mac)
|
61
60
|
end
|
62
61
|
|
63
|
-
context
|
64
|
-
it
|
65
|
-
expect(last_response.body).to be_include("action='https://
|
62
|
+
context 'with default options' do
|
63
|
+
it 'has the default action tag value' do
|
64
|
+
expect(last_response.body).to be_include("action='https://www.swedbank.lv/banklink'")
|
66
65
|
end
|
67
66
|
|
68
|
-
it
|
69
|
-
expect(last_response.body).to be_include("action='https://
|
67
|
+
it 'has the default VK_LANG value' do
|
68
|
+
expect(last_response.body).to be_include("action='https://www.swedbank.lv/banklink'")
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
73
|
-
context
|
72
|
+
context 'with custom options' do
|
74
73
|
let(:app){ Rack::Builder.new do |b|
|
75
|
-
b.use Rack::Session::Cookie, {:
|
76
|
-
b.use(OmniAuth::Strategies::Swedbank,
|
77
|
-
:
|
74
|
+
b.use Rack::Session::Cookie, {secret: 'abc123'}
|
75
|
+
b.use(OmniAuth::Strategies::Swedbank, PRIVATE_KEY, PUBLIC_KEY, 'MY_SND_ID', 'MY_REC_ID',
|
76
|
+
site: 'https://test.lv/banklink')
|
78
77
|
b.run lambda{|env| [404, {}, ['Not Found']]}
|
79
78
|
end.to_app }
|
80
79
|
|
81
|
-
it
|
80
|
+
it 'has the custom action tag value' do
|
82
81
|
expect(last_response.body).to be_include("action='https://test.lv/banklink'")
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
86
|
-
context
|
85
|
+
context 'with non-existant private key files' do
|
87
86
|
let(:app){ Rack::Builder.new do |b|
|
88
|
-
b.use Rack::Session::Cookie, {:
|
89
|
-
b.use(OmniAuth::Strategies::Swedbank,
|
87
|
+
b.use Rack::Session::Cookie, {secret: 'abc123'}
|
88
|
+
b.use(OmniAuth::Strategies::Swedbank, 'missing-private-key-file.pem', PUBLIC_KEY, 'MY_SND_ID', 'MY_REC_ID')
|
90
89
|
b.run lambda{|env| [404, {}, ['Not Found']]}
|
91
90
|
end.to_app }
|
92
91
|
|
93
|
-
it
|
92
|
+
it 'redirects to /auth/failure with appropriate query params' do
|
94
93
|
expect(last_response.status).to eq(302)
|
95
|
-
expect(last_response.headers[
|
94
|
+
expect(last_response.headers['Location']).to eq('/auth/failure?message=private_key_load_err&strategy=swedbank')
|
96
95
|
end
|
97
96
|
end
|
98
97
|
end
|
99
98
|
|
100
|
-
context
|
99
|
+
context 'callback phase' do
|
101
100
|
let(:auth_hash){ last_request.env['omniauth.auth'] }
|
102
101
|
|
103
|
-
context
|
102
|
+
context 'with valid response' do
|
104
103
|
before do
|
105
|
-
post
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
104
|
+
post '/auth/swedbank/callback',
|
105
|
+
'VK_SERVICE' => '3003',
|
106
|
+
'VK_VERSION' => '008',
|
107
|
+
'VK_SND_ID' => 'HP',
|
108
|
+
'VK_REC_ID' => 'MY_REC_ID',
|
109
|
+
'VK_NONCE' => 'pXXXlocalhostX3000b41292810c0345a7b3770b1c807bed7a',
|
110
|
+
'VK_INFO' => 'ISIK:123456-12345;NIMI:Example User',
|
111
|
+
'VK_MAC' => 'cmXyp2My7P9pTgrzqJeg7qH+NPCuyaiGNpQIrcCr6S44w0bH+Ao4WDViqytaPH2vENooVPXDSgOcBqHTg44gJ9FlrhI5StiouHVhjpCcWg+h/ERcyc8w58PjsEmdsd4BIpaGXNyhvcIKdWfNwYA1UCIrmFsPAPWfVeorNxp81E7pvY4p4zsqMF80YZ7/RdOpjrtuXJ4nYJ7d+2fXJKKmUlqArCc786DJdb/z8wVDSNA9BZxnf8EE6s//p9gzqLPAg/T9Xp/2024n2JtC6kwsWF614bn64LEZz5c8owZth6FV+2fjnzHxOiifOe+jc9SRstCLITK6Y0j+6n8auiEZ5g==',
|
112
|
+
'VK_LANG' => 'LAT',
|
113
|
+
'VK_ENCODING' => 'UTF-8'
|
115
114
|
end
|
116
115
|
|
117
|
-
it
|
118
|
-
expect(auth_hash.uid).to eq(
|
116
|
+
it 'sets the correct uid value in the auth hash' do
|
117
|
+
expect(auth_hash.uid).to eq('123456-12345')
|
119
118
|
end
|
120
119
|
|
121
|
-
it
|
122
|
-
expect(auth_hash.info.full_name).to eq(
|
120
|
+
it 'sets the correct info.full_name value in the auth hash' do
|
121
|
+
expect(auth_hash.info.full_name).to eq('Example User')
|
123
122
|
end
|
124
123
|
end
|
125
124
|
|
126
|
-
context
|
125
|
+
context 'with non-existant public key file' do
|
127
126
|
let(:app){ Rack::Builder.new do |b|
|
128
|
-
b.use Rack::Session::Cookie, {:
|
129
|
-
b.use(OmniAuth::Strategies::Swedbank,
|
127
|
+
b.use Rack::Session::Cookie, {secret: 'abc123'}
|
128
|
+
b.use(OmniAuth::Strategies::Swedbank, PRIVATE_KEY, 'missing-public-key-file.pem', 'MY_SND_ID', 'MY_REC_ID')
|
130
129
|
b.run lambda{|env| [404, {}, ['Not Found']]}
|
131
130
|
end.to_app }
|
132
131
|
|
133
|
-
it
|
134
|
-
post
|
132
|
+
it 'redirects to /auth/failure with appropriate query params' do
|
133
|
+
post '/auth/swedbank/callback' # Params are not important, because we're testing public key loading
|
135
134
|
expect(last_response.status).to eq(302)
|
136
|
-
expect(last_response.headers[
|
135
|
+
expect(last_response.headers['Location']).to eq('/auth/failure?message=public_key_load_err&strategy=swedbank')
|
137
136
|
end
|
138
137
|
end
|
139
138
|
|
140
|
-
context
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
:VK_LANG => :'LAT'
|
139
|
+
context 'with invalid response' do
|
140
|
+
it 'detects invalid signature' do
|
141
|
+
post '/auth/swedbank/callback',
|
142
|
+
'VK_SERVICE' => '3003',
|
143
|
+
'VK_VERSION' => '008',
|
144
|
+
'VK_SND_ID' => 'HP',
|
145
|
+
'VK_REC_ID' => 'MY_REC_ID',
|
146
|
+
'VK_NONCE' => 'pXXXlocalhostX3000b41292810c0345a7b3770b1c807bed7a',
|
147
|
+
'VK_INFO' => 'ISIK:123456-12345;NIMI:Example User',
|
148
|
+
'VK_MAC' => 'invalid signature',
|
149
|
+
'VK_LANG' => 'LAT',
|
150
|
+
'VK_ENCODING' => 'UTF-8'
|
153
151
|
|
154
152
|
expect(last_response.status).to eq(302)
|
155
|
-
expect(last_response.headers[
|
153
|
+
expect(last_response.headers['Location']).to eq('/auth/failure?message=invalid_response_signature_err&strategy=swedbank')
|
156
154
|
end
|
157
155
|
|
158
|
-
it
|
159
|
-
post
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
156
|
+
it 'detects unsupported VK_SERVICE values' do
|
157
|
+
post '/auth/swedbank/callback',
|
158
|
+
'VK_SERVICE' => '3004',
|
159
|
+
'VK_VERSION' => '008',
|
160
|
+
'VK_SND_ID' => 'HP',
|
161
|
+
'VK_REC_ID' => 'MY_REC_ID',
|
162
|
+
'VK_NONCE' => 'pXXXlocalhostX3000b41292810c0345a7b3770b1c807bed7a',
|
163
|
+
'VK_INFO' => 'ISIK:123456-12345;NIMI:Example User',
|
164
|
+
'VK_MAC' => 'cmXyp2My7P9pTgrzqJeg7qH+NPCuyaiGNpQIrcCr6S44w0bH+Ao4WDViqytaPH2vENooVPXDSgOcBqHTg44gJ9FlrhI5StiouHVhjpCcWg+h/ERcyc8w58PjsEmdsd4BIpaGXNyhvcIKdWfNwYA1UCIrmFsPAPWfVeorNxp81E7pvY4p4zsqMF80YZ7/RdOpjrtuXJ4nYJ7d+2fXJKKmUlqArCc786DJdb/z8wVDSNA9BZxnf8EE6s//p9gzqLPAg/T9Xp/2024n2JtC6kwsWF614bn64LEZz5c8owZth6FV+2fjnzHxOiifOe+jc9SRstCLITK6Y0j+6n8auiEZ5g==',
|
165
|
+
'VK_LANG' => 'LAT',
|
166
|
+
'VK_ENCODING' => 'UTF-8'
|
169
167
|
|
170
168
|
expect(last_response.status).to eq(302)
|
171
|
-
expect(last_response.headers[
|
169
|
+
expect(last_response.headers['Location']).to eq('/auth/failure?message=unsupported_response_service_err&strategy=swedbank')
|
172
170
|
end
|
173
171
|
|
174
|
-
it
|
175
|
-
post
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
172
|
+
it 'detects unsupported VK_VERSION values' do
|
173
|
+
post '/auth/swedbank/callback',
|
174
|
+
'VK_SERVICE' => '3003',
|
175
|
+
'VK_VERSION' => '009',
|
176
|
+
'VK_SND_ID' => 'HP',
|
177
|
+
'VK_REC_ID' => 'MY_REC_ID',
|
178
|
+
'VK_NONCE' => 'pXXXlocalhostX3000b41292810c0345a7b3770b1c807bed7a',
|
179
|
+
'VK_INFO' => 'ISIK:123456-12345;NIMI:Example User',
|
180
|
+
'VK_MAC' => 'cmXyp2My7P9pTgrzqJeg7qH+NPCuyaiGNpQIrcCr6S44w0bH+Ao4WDViqytaPH2vENooVPXDSgOcBqHTg44gJ9FlrhI5StiouHVhjpCcWg+h/ERcyc8w58PjsEmdsd4BIpaGXNyhvcIKdWfNwYA1UCIrmFsPAPWfVeorNxp81E7pvY4p4zsqMF80YZ7/RdOpjrtuXJ4nYJ7d+2fXJKKmUlqArCc786DJdb/z8wVDSNA9BZxnf8EE6s//p9gzqLPAg/T9Xp/2024n2JtC6kwsWF614bn64LEZz5c8owZth6FV+2fjnzHxOiifOe+jc9SRstCLITK6Y0j+6n8auiEZ5g==',
|
181
|
+
'VK_LANG' => 'LAT',
|
182
|
+
'VK_ENCODING' => 'UTF-8'
|
185
183
|
|
186
184
|
expect(last_response.status).to eq(302)
|
187
|
-
expect(last_response.headers[
|
185
|
+
expect(last_response.headers['Location']).to eq('/auth/failure?message=unsupported_response_version_err&strategy=swedbank')
|
188
186
|
end
|
189
187
|
|
190
|
-
it
|
191
|
-
post
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
188
|
+
it 'detects unsupported VK_ENCODING values' do
|
189
|
+
post '/auth/swedbank/callback',
|
190
|
+
'VK_SERVICE' => '3003',
|
191
|
+
'VK_VERSION' => '008',
|
192
|
+
'VK_SND_ID' => 'HP',
|
193
|
+
'VK_REC_ID' => 'MY_REC_ID',
|
194
|
+
'VK_NONCE' => 'pXXXlocalhostX3000b41292810c0345a7b3770b1c807bed7a',
|
195
|
+
'VK_INFO' => 'ISIK:123456-12345;NIMI:Example User',
|
196
|
+
'VK_MAC' => 'cmXyp2My7P9pTgrzqJeg7qH+NPCuyaiGNpQIrcCr6S44w0bH+Ao4WDViqytaPH2vENooVPXDSgOcBqHTg44gJ9FlrhI5StiouHVhjpCcWg+h/ERcyc8w58PjsEmdsd4BIpaGXNyhvcIKdWfNwYA1UCIrmFsPAPWfVeorNxp81E7pvY4p4zsqMF80YZ7/RdOpjrtuXJ4nYJ7d+2fXJKKmUlqArCc786DJdb/z8wVDSNA9BZxnf8EE6s//p9gzqLPAg/T9Xp/2024n2JtC6kwsWF614bn64LEZz5c8owZth6FV+2fjnzHxOiifOe+jc9SRstCLITK6Y0j+6n8auiEZ5g==',
|
197
|
+
'VK_LANG' => 'LAT',
|
198
|
+
'VK_ENCODING' => 'ASCII'
|
201
199
|
|
202
200
|
expect(last_response.status).to eq(302)
|
203
|
-
expect(last_response.headers[
|
201
|
+
expect(last_response.headers['Location']).to eq('/auth/failure?message=unsupported_response_encoding_err&strategy=swedbank')
|
204
202
|
end
|
205
|
-
|
206
203
|
end
|
207
204
|
end
|
208
|
-
end
|
205
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,11 +7,13 @@ require 'omniauth-swedbank'
|
|
7
7
|
|
8
8
|
RSpec.configure do |config|
|
9
9
|
config.add_setting('cert_folder')
|
10
|
-
config.cert_folder = File.expand_path('
|
10
|
+
config.cert_folder = File.expand_path('../certs', __FILE__)
|
11
11
|
|
12
12
|
config.include Rack::Test::Methods
|
13
13
|
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
14
14
|
config.expect_with :rspec do |c|
|
15
15
|
c.syntax = :expect
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
18
|
+
|
19
|
+
I18n.enforce_available_locales = false
|
metadata
CHANGED
@@ -1,142 +1,153 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-swedbank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
7
|
+
- MAK IT
|
8
8
|
- Jānis Kiršteins
|
9
|
+
- Kristaps Ērglis
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: omniauth
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
18
|
requirements:
|
19
|
-
- - ~>
|
19
|
+
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
25
|
requirements:
|
27
|
-
- - ~>
|
26
|
+
- - "~>"
|
28
27
|
- !ruby/object:Gem::Version
|
29
28
|
version: '1.0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: i18n
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
30
43
|
- !ruby/object:Gem::Dependency
|
31
44
|
name: rack-test
|
32
45
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
46
|
requirements:
|
35
|
-
- -
|
47
|
+
- - ">="
|
36
48
|
- !ruby/object:Gem::Version
|
37
49
|
version: '0'
|
38
50
|
type: :development
|
39
51
|
prerelease: false
|
40
52
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
53
|
requirements:
|
43
|
-
- -
|
54
|
+
- - ">="
|
44
55
|
- !ruby/object:Gem::Version
|
45
56
|
version: '0'
|
46
57
|
- !ruby/object:Gem::Dependency
|
47
58
|
name: rspec
|
48
59
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
60
|
requirements:
|
51
|
-
- - ~>
|
61
|
+
- - "~>"
|
52
62
|
- !ruby/object:Gem::Version
|
53
63
|
version: '2.7'
|
54
64
|
type: :development
|
55
65
|
prerelease: false
|
56
66
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
67
|
requirements:
|
59
|
-
- - ~>
|
68
|
+
- - "~>"
|
60
69
|
- !ruby/object:Gem::Version
|
61
70
|
version: '2.7'
|
62
71
|
- !ruby/object:Gem::Dependency
|
63
72
|
name: bundler
|
64
73
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
74
|
requirements:
|
67
|
-
- - ~>
|
75
|
+
- - "~>"
|
68
76
|
- !ruby/object:Gem::Version
|
69
77
|
version: '1.3'
|
70
78
|
type: :development
|
71
79
|
prerelease: false
|
72
80
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
81
|
requirements:
|
75
|
-
- - ~>
|
82
|
+
- - "~>"
|
76
83
|
- !ruby/object:Gem::Version
|
77
84
|
version: '1.3'
|
78
85
|
- !ruby/object:Gem::Dependency
|
79
86
|
name: rake
|
80
87
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
88
|
requirements:
|
83
|
-
- -
|
89
|
+
- - ">="
|
84
90
|
- !ruby/object:Gem::Version
|
85
91
|
version: '0'
|
86
92
|
type: :development
|
87
93
|
prerelease: false
|
88
94
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
95
|
requirements:
|
91
|
-
- -
|
96
|
+
- - ">="
|
92
97
|
- !ruby/object:Gem::Version
|
93
98
|
version: '0'
|
94
99
|
description: OmniAuth strategy for Swedbank Banklink
|
95
100
|
email:
|
101
|
+
- admin@makit.lv
|
96
102
|
- janis@montadigital.com
|
103
|
+
- kristaps.erglis@gmail.com
|
97
104
|
executables: []
|
98
105
|
extensions: []
|
99
106
|
extra_rdoc_files: []
|
100
107
|
files:
|
101
|
-
- .gitignore
|
108
|
+
- ".gitignore"
|
109
|
+
- ".travis.yml"
|
102
110
|
- Gemfile
|
103
111
|
- LICENSE.txt
|
104
112
|
- README.md
|
105
113
|
- Rakefile
|
106
|
-
- certs/request.private.pem
|
107
|
-
- certs/response.public.pem
|
108
114
|
- lib/omniauth-swedbank.rb
|
115
|
+
- lib/omniauth/locales/omniauth.en.yml
|
116
|
+
- lib/omniauth/locales/omniauth.lv.yml
|
109
117
|
- lib/omniauth/strategies/swedbank.rb
|
110
118
|
- lib/omniauth/swedbank.rb
|
111
119
|
- lib/omniauth/swedbank/version.rb
|
112
120
|
- omniauth-swedbank.gemspec
|
121
|
+
- spec/certs/request.private.pem
|
122
|
+
- spec/certs/response.public.pem
|
113
123
|
- spec/omniauth/strategies/swedbank_spec.rb
|
114
124
|
- spec/spec_helper.rb
|
115
|
-
homepage:
|
125
|
+
homepage: https://github.com/mak-it/omniauth-swedbank
|
116
126
|
licenses:
|
117
127
|
- MIT
|
128
|
+
metadata: {}
|
118
129
|
post_install_message:
|
119
130
|
rdoc_options: []
|
120
131
|
require_paths:
|
121
132
|
- lib
|
122
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
134
|
requirements:
|
125
|
-
- -
|
135
|
+
- - ">="
|
126
136
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
137
|
+
version: 2.2.2
|
128
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
139
|
requirements:
|
131
|
-
- -
|
140
|
+
- - ">="
|
132
141
|
- !ruby/object:Gem::Version
|
133
142
|
version: '0'
|
134
143
|
requirements: []
|
135
144
|
rubyforge_project:
|
136
|
-
rubygems_version:
|
145
|
+
rubygems_version: 2.4.8
|
137
146
|
signing_key:
|
138
|
-
specification_version:
|
147
|
+
specification_version: 4
|
139
148
|
summary: OmniAuth strategy for Swedbank Banklink
|
140
149
|
test_files:
|
150
|
+
- spec/certs/request.private.pem
|
151
|
+
- spec/certs/response.public.pem
|
141
152
|
- spec/omniauth/strategies/swedbank_spec.rb
|
142
153
|
- spec/spec_helper.rb
|