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 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
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-gemset
19
+ .ruby-version
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.6
4
+ - 2.3.3
5
+ - 2.4.1
6
+ script: bundle exec rspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Jānis Kiršteins
1
+ Copyright (c) 2017 MAK IT, Jānis Kiršteins
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
- # Omniauth::Swedbank
1
+ # Omniauth Swedbank
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
 
@@ -1 +1,4 @@
1
- require 'omniauth/swedbank'
1
+ require 'omniauth/swedbank'
2
+ require 'i18n'
3
+
4
+ I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'omniauth', 'locales', '*.yml')]
@@ -0,0 +1,5 @@
1
+ en:
2
+ omniauth:
3
+ swedbank:
4
+ please_wait: Please wait...
5
+ click_here_if_not_redirected: Click here, if not redirected automatically
@@ -0,0 +1,5 @@
1
+ lv:
2
+ omniauth:
3
+ swedbank:
4
+ please_wait: Lūdzu uzgaidiet...
5
+ click_here_if_not_redirected: Spiediet šeit, ja pāradresācija nenotiek automātiski
@@ -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
- AUTH_SERVICE_ID = :"4002"
13
- AUTH_SERVICE_VERSION = :"008" # This value must not be used as a number, so as to not lose the padding
14
- # Padding is important when generating the VK_MAC value
9
+ AUTH_SERVICE = '4002'
10
+ AUTH_VERSION = '008'
15
11
 
16
- args [:private_key_file, :public_key_file, :snd_id, :rec_id]
12
+ args [:private_key, :public_key, :snd_id, :rec_id]
17
13
 
18
- option :private_key_file, nil
19
- option :public_key_file, nil
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, "swedbank"
24
- option :site, "https://ib.swedbank.lv/banklink"
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 nonce
31
- return @nonce if @nonce
32
- @nonce = ((full_host.gsub(/[\:\/]/, "X") + SecureRandom.uuid.gsub("-", "")).rjust 50, " ")[-50, 50]
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 append_value_to_signature(value, signature = "")
36
- signature << "#{value.to_s.bytesize.to_s.rjust(3, '0')}#{value}"
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
- sig_str = append_value_to_signature(AUTH_SERVICE_ID) # VK_SERVICE
41
- append_value_to_signature(AUTH_SERVICE_VERSION, sig_str) # VK_VERSION
42
- append_value_to_signature(options.snd_id, sig_str) # VK_SND_ID
43
- append_value_to_signature(options.rec_id, sig_str) # VK_REC_ID
44
- append_value_to_signature(nonce, sig_str) # VK_NONCE
45
- append_value_to_signature(callback_url, sig_str) # VK_RETURN
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 (priv_key)
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[:VK_INFO.to_s].match(/ISIK:(\d{6}\-\d{5})/)[1]
48
+ request.params['VK_INFO'].match(/ISIK:(\d{6}\-\d{5})/)[1]
54
49
  end
55
50
 
56
51
  info do
57
52
  {
58
- :full_name => request.params[:VK_INFO.to_s].match(/NIMI:(.+)/)[1]
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(File.read(options.public_key_file || "")).public_key
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[:VK_SERVICE.to_s] != "3003"
68
+ if request.params['VK_SERVICE'] != '3003'
70
69
  return fail!(:unsupported_response_service_err)
71
70
  end
72
71
 
73
- if request.params[:VK_VERSION.to_s] != "008"
72
+ if request.params['VK_VERSION'] != '008'
74
73
  return fail!(:unsupported_response_version_err)
75
74
  end
76
75
 
77
- if request.params[:VK_ENCODING.to_s] != "UTF-8"
76
+ if request.params['VK_ENCODING'] != 'UTF-8'
78
77
  return fail!(:unsupported_response_encoding_err)
79
78
  end
80
79
 
81
- sig_str = append_value_to_signature(request.params[:VK_SERVICE.to_s])
82
- append_value_to_signature(request.params[:VK_VERSION.to_s], sig_str)
83
- append_value_to_signature(request.params[:VK_SND_ID.to_s], sig_str)
84
- append_value_to_signature(request.params[:VK_REC_ID.to_s], sig_str)
85
- append_value_to_signature(request.params[:VK_NONCE.to_s], sig_str)
86
- append_value_to_signature(request.params[:VK_INFO.to_s], sig_str)
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[:VK_MAC.to_s])
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(File.read(options.private_key_file || ""))
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.config.form_css = nil
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
- form.html "<input type=\"hidden\" name=\"VK_SERVICE\" value=\"#{AUTH_SERVICE_ID}\" />"
110
- form.html "<input type=\"hidden\" name=\"VK_VERSION\" value=\"#{AUTH_SERVICE_VERSION}\" />"
111
- form.html "<input type=\"hidden\" name=\"VK_SND_ID\" value=\"#{options.snd_id}\" />"
112
- form.html "<input type=\"hidden\" name=\"VK_REC_ID\" value=\"#{options.rec_id}\" />"
113
- form.html "<input type=\"hidden\" name=\"VK_NONCE\" value=\"#{nonce}\" />"
114
- form.html "<input type=\"hidden\" name=\"VK_RETURN\" value=\"#{callback_url}\" />"
115
- form.html "<input type=\"hidden\" name=\"VK_LANG\" value=\"LAT\" />"
116
- form.html "<input type=\"hidden\" name=\"VK_MAC\" value=\"#{signature priv_key}\" />"
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 "Click here if not redirected automatically ..."
121
+ form.button I18n.t('omniauth.swedbank.click_here_if_not_redirected')
119
122
 
120
- form.instance_variable_set("@html",
121
- form.to_html.gsub("</form>", "</form><script type=\"text/javascript\">document.forms[0].submit();</script>"))
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
@@ -1,2 +1,2 @@
1
1
  require 'omniauth/swedbank/version'
2
- require 'omniauth/strategies/swedbank'
2
+ require 'omniauth/strategies/swedbank'
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Swedbank
3
- VERSION = "0.0.3"
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -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 = "omniauth-swedbank"
7
+ spec.name = 'omniauth-swedbank'
8
8
  spec.version = Omniauth::Swedbank::VERSION
9
- spec.authors = ["Jānis Kiršteins"]
10
- spec.email = ["janis@montadigital.com"]
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 = "MIT"
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 = ["lib"]
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
- PRIVATE_KEY_FILE = File.join RSpec.configuration.cert_folder, "request.private.pem"
6
- PUBLIC_KEY_FILE = File.join RSpec.configuration.cert_folder, "response.public.pem"
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, {:secret => "abc123"}
10
- b.use(OmniAuth::Strategies::Swedbank, PRIVATE_KEY_FILE, PUBLIC_KEY_FILE, :"MY_SND_ID", :"MY_REC_ID")
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 "request phase" do
17
+ context 'request phase' do
20
18
  EXPECTED_VALUES = {
21
- :VK_SERVICE => :"4002",
22
- :VK_VERSION => :"008",
23
- :VK_SND_ID => :MY_SND_ID,
24
- :VK_REC_ID => :MY_REC_ID,
25
- :VK_RETURN => :"http://example.org/auth/swedbank/callback"
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 "displays a single form" do
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 "has JavaScript code to submit the form after it's created" do
36
- expect(last_response.body).to be_include("</form><script type=\"text/javascript\">document.forms[0].submit();</script>")
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 "has a 50 byte long nonce field value" do
47
- expect(last_response_nonce.bytesize).to eq(50)
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 "has a correct VK_MAC signature" do
48
+ it 'has a correct VK_MAC signature' do
51
49
  sig_str =
52
- "0044002" + # VK_SERVICE
53
- "003008" + # VK_VERSION
54
- "009MY_SND_ID" + # VK_SND_ID
55
- "009MY_REC_ID" + # VK_REC_ID
56
- "050" + last_response_nonce + # VK_NONCE
57
- "041#{EXPECTED_VALUES[:VK_RETURN]}" # V_RETURN
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 "with default options" do
64
- it "has the default action tag value" do
65
- expect(last_response.body).to be_include("action='https://ib.swedbank.lv/banklink'")
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 "has the default VK_LANG value" do
69
- expect(last_response.body).to be_include("action='https://ib.swedbank.lv/banklink'")
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 "with custom options" do
72
+ context 'with custom options' do
74
73
  let(:app){ Rack::Builder.new do |b|
75
- b.use Rack::Session::Cookie, {:secret => "abc123"}
76
- b.use(OmniAuth::Strategies::Swedbank, PRIVATE_KEY_FILE, PUBLIC_KEY_FILE, :"MY_SND_ID", :"MY_REC_ID",
77
- :site => "https://test.lv/banklink")
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 "has the custom action tag value" do
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 "with non-existant private key files" do
85
+ context 'with non-existant private key files' do
87
86
  let(:app){ Rack::Builder.new do |b|
88
- b.use Rack::Session::Cookie, {:secret => "abc123"}
89
- b.use(OmniAuth::Strategies::Swedbank, "missing-private-key-file.pem", PUBLIC_KEY_FILE, :"MY_SND_ID", :"MY_REC_ID")
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 "redirects to /auth/failure with appropriate query params" do
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["Location"]).to eq("/auth/failure?message=private_key_load_err&strategy=swedbank")
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 "callback phase" do
99
+ context 'callback phase' do
101
100
  let(:auth_hash){ last_request.env['omniauth.auth'] }
102
101
 
103
- context "with valid response" do
102
+ context 'with valid response' do
104
103
  before do
105
- post :'/auth/swedbank/callback',
106
- :VK_SERVICE => :'3003',
107
- :VK_VERSION => :'008',
108
- :VK_SND_ID => :"HP",
109
- :VK_REC_ID => :"MY_REC_ID",
110
- :VK_NONCE => :"pXXXlocalhostX3000b41292810c0345a7b3770b1c807bed7a",
111
- :VK_INFO => :'ISIK:123456-12345;NIMI:Example User',
112
- :VK_MAC => :"cmXyp2My7P9pTgrzqJeg7qH+NPCuyaiGNpQIrcCr6S44w0bH+Ao4WDViqytaPH2vENooVPXDSgOcBqHTg44gJ9FlrhI5StiouHVhjpCcWg+h/ERcyc8w58PjsEmdsd4BIpaGXNyhvcIKdWfNwYA1UCIrmFsPAPWfVeorNxp81E7pvY4p4zsqMF80YZ7/RdOpjrtuXJ4nYJ7d+2fXJKKmUlqArCc786DJdb/z8wVDSNA9BZxnf8EE6s//p9gzqLPAg/T9Xp/2024n2JtC6kwsWF614bn64LEZz5c8owZth6FV+2fjnzHxOiifOe+jc9SRstCLITK6Y0j+6n8auiEZ5g==",
113
- :VK_ENCODING => :'UTF-8',
114
- :VK_LANG => :'LAT'
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 "sets the correct uid value in the auth hash" do
118
- expect(auth_hash.uid).to eq("123456-12345")
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 "sets the correct info.full_name value in the auth hash" do
122
- expect(auth_hash.info.full_name).to eq("Example User")
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 "with non-existant public key file" do
125
+ context 'with non-existant public key file' do
127
126
  let(:app){ Rack::Builder.new do |b|
128
- b.use Rack::Session::Cookie, {:secret => "abc123"}
129
- b.use(OmniAuth::Strategies::Swedbank, PRIVATE_KEY_FILE, "missing-public-key-file.pem", "MY_SND_ID", "MY_REC_ID")
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 "redirects to /auth/failure with appropriate query params" do
134
- post :'/auth/swedbank/callback' # Params are not important, because we're testing public key loading
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["Location"]).to eq("/auth/failure?message=public_key_load_err&strategy=swedbank")
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 "with invalid response" do
141
-
142
- it "detects invalid signature" do
143
- post :'/auth/swedbank/callback',
144
- :VK_SERVICE => :'3003',
145
- :VK_VERSION => :'008',
146
- :VK_SND_ID => :"HP",
147
- :VK_REC_ID => :"MY_REC_ID",
148
- :VK_NONCE => :'pXXXlocalhostX3000df346e9e453d43cd9c3c4076030d9e54',
149
- :VK_INFO => :'ISIK:123456-12345;NIMI:Example User',
150
- :VK_MAC => "invalid signature",
151
- :VK_ENCODING => :'UTF-8',
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["Location"]).to eq("/auth/failure?message=invalid_response_signature_err&strategy=swedbank")
153
+ expect(last_response.headers['Location']).to eq('/auth/failure?message=invalid_response_signature_err&strategy=swedbank')
156
154
  end
157
155
 
158
- it "detects unsupported VK_SERVICE values" do
159
- post :'/auth/swedbank/callback',
160
- :VK_SERVICE => :'3004',
161
- :VK_VERSION => :'008',
162
- :VK_SND_ID => :"HP",
163
- :VK_REC_ID => :"MY_REC_ID",
164
- :VK_NONCE => :'pXXXlocalhostX3000df2afdbd66ee4c3a998b72cfd3d7d131',
165
- :VK_INFO => :'ISIK:123456-12345;NIMI:Example User',
166
- :VK_MAC => :"tzGu5AxwaEMwAjkY8zh796NQ45QSEshuFiT0VnOdDN3gZPYlAcmm5jPs+j17U1rCKvz6tdKn9I8u+OUcV95+1Sa34dZ/09KrUgwDrOej/djJZ2lg5MgGLAftDsRomcCCuBppQvjdzhCvNeA2OAWPbl7Enn6HVjvb3esJY6D80bYIPm48DHDhhHbdcSwHubFeizyw9syviFsN3xVkhr5YS7W1/owXh/jeHSf8cqLVSzRyShU/JnJfevNsXDpSHbphA5Q4n5q5y0EcuA6/wW2qc2o5nKQjDDhZgxkWYKz6YpVj8zC2x/LXUkmJ+r1K0Slw2lhwEcP2tgIdThkAaT8MYQ==",
167
- :VK_ENCODING => :'UTF-8',
168
- :VK_LANG => :'LAT'
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["Location"]).to eq("/auth/failure?message=unsupported_response_service_err&strategy=swedbank")
169
+ expect(last_response.headers['Location']).to eq('/auth/failure?message=unsupported_response_service_err&strategy=swedbank')
172
170
  end
173
171
 
174
- it "detects unsupported VK_VERSION values" do
175
- post :'/auth/swedbank/callback',
176
- :VK_SERVICE => :'3003',
177
- :VK_VERSION => :'009',
178
- :VK_SND_ID => :"HP",
179
- :VK_REC_ID => :"MY_REC_ID",
180
- :VK_NONCE => :'pXXXlocalhostX300023f78258d685424584f4e859b5d480f5',
181
- :VK_INFO => :'ISIK:123456-12345;NIMI:Example User',
182
- :VK_MAC => :"0KACnfCZZW2pQnFGttOXMrQRnmYQj45SwqIa5SbKhybJlP1GaXaoa5VYa+xGAnizx+YKbYQsXchXbeNIlQNrQ8/gedByzJtNFI4s4VIaU0tp7P83BjbzYfSMwvIImZvlFyVPgey8Va06fPGi+jdoUp7Dr8vwf6eAzxQhyVjEEYVR+axkAJP9+driMqTKQaxMlctWnivxf8stjI1ElmcdurndLbVnmHLTw6AichmzqUfvfXE3wh4XCVZtD+7VBPvbn4eKXif61cNfkOO/+nNap1buW8RLQirL7Eis//MmWoGSW8H5605DAAK9Ui7CNoB279Ww05pY4wsP7KZdiJ4WCA==",
183
- :VK_ENCODING => :'UTF-8',
184
- :VK_LANG => :'LAT'
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["Location"]).to eq("/auth/failure?message=unsupported_response_version_err&strategy=swedbank")
185
+ expect(last_response.headers['Location']).to eq('/auth/failure?message=unsupported_response_version_err&strategy=swedbank')
188
186
  end
189
187
 
190
- it "detects unsupported VK_ENCODING values" do
191
- post :'/auth/swedbank/callback',
192
- :VK_SERVICE => :'3003',
193
- :VK_VERSION => :'008',
194
- :VK_SND_ID => :"HP",
195
- :VK_REC_ID => :"MY_REC_ID",
196
- :VK_NONCE => :"pXXXlocalhostX3000b41292810c0345a7b3770b1c807bed7a",
197
- :VK_INFO => :'ISIK:123456-12345;NIMI:Example User',
198
- :VK_MAC => :"cmXyp2My7P9pTgrzqJeg7qH+NPCuyaiGNpQIrcCr6S44w0bH+Ao4WDViqytaPH2vENooVPXDSgOcBqHTg44gJ9FlrhI5StiouHVhjpCcWg+h/ERcyc8w58PjsEmdsd4BIpaGXNyhvcIKdWfNwYA1UCIrmFsPAPWfVeorNxp81E7pvY4p4zsqMF80YZ7/RdOpjrtuXJ4nYJ7d+2fXJKKmUlqArCc786DJdb/z8wVDSNA9BZxnf8EE6s//p9gzqLPAg/T9Xp/2024n2JtC6kwsWF614bn64LEZz5c8owZth6FV+2fjnzHxOiifOe+jc9SRstCLITK6Y0j+6n8auiEZ5g==",
199
- :VK_ENCODING => :'ASCII',
200
- :VK_LANG => :'LAT'
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["Location"]).to eq("/auth/failure?message=unsupported_response_encoding_err&strategy=swedbank")
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('../../certs', __FILE__)
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.3
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: 2013-04-29 00:00:00.000000000 Z
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: '0'
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: 1.8.25
145
+ rubygems_version: 2.4.8
137
146
  signing_key:
138
- specification_version: 3
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