omniauth-nordea 0.0.2

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,19 @@
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
18
+ .ruby-gemset
19
+ .ruby-version
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-nordea.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jānis Kiršteins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # Omniauth::Nordea
2
+
3
+ Omniauth strategy for using Nordea Latvia as an authentication service provider.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/omniauth-nordea.png)](http://badge.fury.io/rb/omniauth-nordea)
6
+ [![Build Status](https://travis-ci.org/kirsis/omniauth-nordea.png?branch=master)](https://travis-ci.org/kirsis/omniauth-nordea)
7
+
8
+ Supported Ruby versions: 1.9.2, 1.9.3 and 2.0.0
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'omniauth-nordea'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install omniauth-nordea
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require 'omniauth/nordea'
2
+ require 'i18n'
3
+ require 'pry'
4
+
5
+ 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
@@ -0,0 +1,2 @@
1
+ require 'omniauth/nordea/version'
2
+ require 'omniauth/strategies/nordea'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Nordea
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,63 @@
1
+ require 'omniauth'
2
+ require 'base64'
3
+ require 'omniauth/strategies/nordea/request_helpers'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Nordea
8
+ PRODUCTION_ENDPOINT = "https://netbank.nordea.com/pnbeid/eidn.jsp"
9
+ TEST_ENDPOINT = "https://netbank.nordea.com/pnbeidtest/eidn.jsp"
10
+
11
+ include OmniAuth::Strategy
12
+
13
+ args [:rcvid, :mac]
14
+
15
+ option :rcvid, nil
16
+ option :mac, nil
17
+
18
+ # Supported algorithms: :sha1 and :md5
19
+ option :hash_algorithm, :sha1
20
+ option :name, "nordea"
21
+ option :endpoint, PRODUCTION_ENDPOINT
22
+
23
+ uid do
24
+ request.params["B02K_CUSTID"].dup.insert(6, "-")
25
+ end
26
+
27
+ info do
28
+ {
29
+ full_name: request.params["B02K_CUSTNAME"].dup.split(" ").reverse.join(" ")
30
+ }
31
+ end
32
+
33
+ def callback_phase
34
+ super
35
+ rescue Exception => e
36
+ fail!(:unknown_callback_err, e)
37
+ end
38
+
39
+ def request_phase
40
+
41
+ param_hash = OmniAuth::Strategies::Nordea.build_request_hash(options.rcvid, options.mac,
42
+ full_host + script_name + callback_path)
43
+ OmniAuth::Strategies::Nordea.sign_hash_in_place(param_hash)
44
+
45
+ # Build redirect form
46
+ OmniAuth.config.form_css = nil
47
+ form = OmniAuth::Form.new(title: I18n.t("omniauth.swedbank.please_wait"), url: options.endpoint)
48
+
49
+ param_hash.each_pair do |k,v|
50
+ form.html "<input type=\"hidden\" name=\"#{k}\" value=\"#{v}\" />"
51
+ end
52
+
53
+ form.button I18n.t("omniauth.swedbank.click_here_if_not_redirected")
54
+
55
+ form.instance_variable_set("@html",
56
+ form.to_html.gsub("</form>", "</form><script type=\"text/javascript\">document.forms[0].submit();</script>"))
57
+ form.to_response
58
+ rescue Exception => e
59
+ fail!(:unknown_request_err, e)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,89 @@
1
+ require 'digest/sha1'
2
+ require 'digest/md5'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Nordea
7
+ class ArgumentError < StandardError; end
8
+
9
+ # 'A01Y_ACTION_ID',
10
+ # 'A01Y_VERS', # 0002 (standard), 0003 (with additional data) or 0004.
11
+ # => Only 0002 supported
12
+ # 'A01Y_RCVID',
13
+ # 'A01Y_LANGCODE', # ET, LV, LT, EN
14
+ # 'A01Y_STAMP', # yyyymmddhhmmssxxxxxx
15
+ # 'A01Y_IDTYPE',
16
+ # 'A01Y_RETLINK',
17
+ # 'A01Y_CANLINK',
18
+ # 'A01Y_REJLINK',
19
+ # 'A01Y_KEYVERS',
20
+ # 'A01Y_ALG', 01 for md5, 02 for sha1
21
+ # 'A01Y_MAC',
22
+
23
+ ALGORITHM_NAMES = { "01" => :md5, "02" => :sha1 }
24
+ SUPPORTED_LANG_CODES = [ :LV, :ET, :LT, :EN ]
25
+ SUPPORTED_VERSIONS = [ "0002" ]
26
+
27
+ class << self
28
+
29
+ def callback_variation(callback_url, status)
30
+ url = URI(callback_url)
31
+ url.query = "omniauth_status=#{status}"
32
+ url
33
+ end
34
+
35
+ # We're counting on receiving an ordered hash
36
+ # This method
37
+ def sign_hash_in_place(hash)
38
+
39
+ signable_string = hash.values.join("&") + "&"
40
+
41
+ digest_class =
42
+ case ALGORITHM_NAMES[ hash["A01Y_ALG"] ]
43
+ when :sha1
44
+ Digest::SHA1
45
+ when :md5
46
+ Digest::MD5
47
+ end
48
+
49
+ hash["A01Y_MAC"] = digest_class.send(:hexdigest, signable_string)
50
+ end
51
+
52
+ def build_request_hash(rcvid, mac, callback_url, opts = {})
53
+ opts = {
54
+ algorithm: :sha1,
55
+ version: "0002",
56
+ langcode: :LV
57
+ }.merge(opts)
58
+
59
+ if !SUPPORTED_LANG_CODES.include?(opts[:langcode])
60
+ raise ArgumentError.new (":langcode must be one of " + SUPPORTED_LANG_CODES.to_s)
61
+ end
62
+
63
+ if !ALGORITHM_NAMES.values.include?(opts[:algorithm])
64
+ raise ArgumentError.new (":algorithm must be one of " + ALGORITHM_NAMES.values.to_s)
65
+ end
66
+
67
+ if !SUPPORTED_VERSIONS.include?(opts[:version])
68
+ raise ArgumentError.new (":version must be one of " + SUPPORTED_VERSIONS.to_s)
69
+ end
70
+
71
+ {
72
+ "A01Y_ACTION_ID" => "701",
73
+ "A01Y_VERS" => opts[:version],
74
+ "A01Y_RCVID" => rcvid,
75
+ "A01Y_LANGCODE" => opts[:langcode],
76
+ "A01Y_STAMP" => "yyyymmddhhmmssxxxxxx",
77
+ "A01Y_IDTYPE" => "02",
78
+ "A01Y_RETLINK" => self.callback_variation(callback_url, "success"),
79
+ "A01Y_CANLINK" => self.callback_variation(callback_url, "cancelled"),
80
+ "A01Y_REJLINK" => self.callback_variation(callback_url, "rejected"),
81
+ "A01Y_KEYVERS" => "0001",
82
+ "A01Y_ALG" => ALGORITHM_NAMES.key(opts[:algorithm]),
83
+ "A01Y_MAC" => mac
84
+ }
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth/nordea/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'omniauth-nordea'
8
+ gem.version = Omniauth::Nordea::VERSION
9
+ gem.authors = ['Jānis Kiršteins', 'Kristaps Ērglis']
10
+ gem.email = ['janis@montadigital.com', 'kristaps.erglis@gmail.com' ]
11
+ gem.description = %q{OmniAuth strategy for Nordea bank}
12
+ gem.summary = %q{OmniAuth strategy for Nordea bank}
13
+ gem.homepage = ''
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.add_runtime_dependency 'omniauth', '~> 1.0'
22
+ gem.add_runtime_dependency 'i18n'
23
+
24
+ gem.add_development_dependency 'rack-test'
25
+ gem.add_development_dependency 'rspec', '~> 2.7'
26
+ gem.add_development_dependency 'bundler', '~> 1.3'
27
+ gem.add_development_dependency 'rake'
28
+ gem.add_development_dependency 'pry'
29
+
30
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Nordea do
4
+
5
+ RCVID = '11111111111'
6
+ MAC = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
7
+
8
+ let(:app){ Rack::Builder.new do |b|
9
+ b.use Rack::Session::Cookie, {:secret => "abc123"}
10
+ b.use OmniAuth::Strategies::Nordea, RCVID, MAC
11
+ b.run lambda{|env| [404, {}, ['Not Found']]}
12
+ end.to_app }
13
+
14
+ context "request phase" do
15
+
16
+ before(:each) { get "/auth/nordea" }
17
+
18
+ it "displays a single form" do
19
+ expect(last_response.status).to eq(200)
20
+ expect(last_response.body.scan('<form').size).to eq(1)
21
+ end
22
+
23
+ it "has JavaScript code to submit the form after it's created" do
24
+ expect(last_response.body).to be_include("</form><script type=\"text/javascript\">document.forms[0].submit();</script>")
25
+ end
26
+
27
+ EXPECTED_VALUES = {
28
+ "A01Y_ACTION_ID" => "701",
29
+ "A01Y_VERS" => "0002",
30
+ "A01Y_RCVID" => RCVID,
31
+ "A01Y_LANGCODE" => "LV",
32
+ "A01Y_STAMP" => "yyyymmddhhmmssxxxxxx",
33
+ "A01Y_IDTYPE" => "02",
34
+ "A01Y_RETLINK" => "http://example.org/auth/nordea/callback?omniauth_status=success",
35
+ "A01Y_CANLINK" => "http://example.org/auth/nordea/callback?omniauth_status=cancelled",
36
+ "A01Y_REJLINK" => "http://example.org/auth/nordea/callback?omniauth_status=rejected",
37
+ "A01Y_KEYVERS" => "0001",
38
+ "A01Y_ALG" => "02",
39
+ "A01Y_MAC" => "c2e09d42e0eaf565ba1b14074f3bdae341b35bce"
40
+ }
41
+
42
+ EXPECTED_VALUES.each_pair do |k,v|
43
+ it "has hidden input field #{k} => #{v}" do
44
+ expect(last_response.body.scan(
45
+ "<input type=\"hidden\" name=\"#{k}\" value=\"#{v}\"").size).to eq(1)
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ context "callback phase" do
52
+ let(:auth_hash){ last_request.env['omniauth.auth'] }
53
+
54
+ context "with valid response" do
55
+ before do
56
+ post :'/auth/nordea/callback',
57
+ "B02K_VERS" => "0002",
58
+ "B02K_TIMESTMP" => "2002014020513320773",
59
+ "B02K_IDNBR" => "f26402f2250340dba8b24c8498fd8c58",
60
+ "B02K_STAMP" => "yyyymmddhhmmssxxxxxx",
61
+ "B02K_CUSTNAME" => "Last First",
62
+ "B02K_KEYVERS" => "0001",
63
+ "B02K_ALG" => "02",
64
+ "B02K_CUSTID" => "12345612345",
65
+ "B02K_CUSTTYPE" => "01",
66
+ "B02K_MAC" => "852E3207E143677B6E622DDF1D27B13979DB8C67"
67
+ end
68
+
69
+ it "sets the correct uid value in the auth hash" do
70
+ expect(auth_hash.uid).to eq("123456-12345")
71
+ end
72
+
73
+ it "sets the correct info.full_name value in the auth hash" do
74
+ expect(auth_hash.info.full_name).to eq("First Last")
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'rspec'
4
+ require 'rack/test'
5
+ require 'omniauth'
6
+ require 'omniauth-nordea'
7
+
8
+ RSpec.configure do |config|
9
+ config.include Rack::Test::Methods
10
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-nordea
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jānis Kiršteins
9
+ - Kristaps Ērglis
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-02-05 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: omniauth
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: i18n
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack-test
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '2.7'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '2.7'
79
+ - !ruby/object:Gem::Dependency
80
+ name: bundler
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '1.3'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '1.3'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rake
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ description: OmniAuth strategy for Nordea bank
128
+ email:
129
+ - janis@montadigital.com
130
+ - kristaps.erglis@gmail.com
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - .gitignore
136
+ - .travis.yml
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - lib/omniauth-nordea.rb
142
+ - lib/omniauth/locales/omniauth.en.yml
143
+ - lib/omniauth/locales/omniauth.lv.yml
144
+ - lib/omniauth/nordea.rb
145
+ - lib/omniauth/nordea/version.rb
146
+ - lib/omniauth/strategies/nordea.rb
147
+ - lib/omniauth/strategies/nordea/request_helpers.rb
148
+ - omniauth-nordea.gemspec
149
+ - spec/omniauth/strategies/nordea_spec.rb
150
+ - spec/spec_helper.rb
151
+ homepage: ''
152
+ licenses:
153
+ - MIT
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.25
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: OmniAuth strategy for Nordea bank
176
+ test_files:
177
+ - spec/omniauth/strategies/nordea_spec.rb
178
+ - spec/spec_helper.rb