omniauth-privatbank-ua 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/README.md +27 -0
- data/Rakefile +8 -0
- data/lib/omniauth-privatbank-ua.rb +2 -0
- data/lib/omniauth-privatbank-ua/version.rb +5 -0
- data/lib/omniauth/strategies/privatbank-ua.rb +140 -0
- data/omniauth-privatbank-ua.gemspec +26 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50e5c27788a4dfe1874385244a11ee309187e4cf
|
4
|
+
data.tar.gz: 64b971ac19382f00f6262dd171a0d043bff8a168
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae2c6029f6e789faca8ddd6ed0456ba90e00f6dbeba3ce22d5372343095691e250bc35186d7ed9297c1e7310b9f8e3d638f45ceb9dfcd4b81714a3472f0fbed0
|
7
|
+
data.tar.gz: a01f79ba1f76cca4dc5e3f64033c7ac94f59a3ac9c14cf9f1936f124478986190fcad1676955366d80b2135b9efd2d6d1ae7b0d81ec152c0e3ffa07190b648e2
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# OmniAuth privatbank.ua
|
2
|
+
|
3
|
+
## Using This Strategy
|
4
|
+
|
5
|
+
First start by adding this gem to your Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'omniauth-privatbank-ua'
|
9
|
+
```
|
10
|
+
|
11
|
+
Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
15
|
+
if Rails.env.production?
|
16
|
+
provider :'privatbank-ua', ENV['ua_privatbank_client_id'], ENV['ua_privatbank_client_secret'],
|
17
|
+
private_key_path: ENV['ua_privatbank_client_private_key_path']
|
18
|
+
else
|
19
|
+
#for some reason in development we get ssl verification errors
|
20
|
+
require 'openssl'
|
21
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
22
|
+
provider OmniAuth::Strategies::PrivatbankUaSandbox, ENV['ua_privatbank_client_id'], ENV['ua_privatbank_client_secret'],
|
23
|
+
private_key_path: ENV['ua_privatbank_client_private_key_path']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class PrivatbankUa < OmniAuth::Strategies::OAuth2
|
7
|
+
class NoCustomerError < StandardError; end
|
8
|
+
option :name, 'privatbank-ua'
|
9
|
+
|
10
|
+
OAUTH_DOMAIN = 'https://bankid.org.ua'
|
11
|
+
DATA_DOMAIN = 'https://biprocessing.org.ua'
|
12
|
+
|
13
|
+
option :client_options, {
|
14
|
+
site: OAUTH_DOMAIN,
|
15
|
+
authorize_url: '/DataAccessService/das/authorize',
|
16
|
+
token_url: '/DataAccessService/oauth/token',
|
17
|
+
token_method: :get
|
18
|
+
}
|
19
|
+
|
20
|
+
option :data_site, DATA_DOMAIN
|
21
|
+
|
22
|
+
uid { raw_info['inn'] }
|
23
|
+
|
24
|
+
info do
|
25
|
+
{
|
26
|
+
:inn => raw_info['inn'],
|
27
|
+
:first_name => raw_info['firstName'],
|
28
|
+
:last_name => raw_info['lastName'],
|
29
|
+
:middle_name => raw_info['middleName'],
|
30
|
+
:email => raw_info['email'],
|
31
|
+
:phone => raw_info['phone']
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
extra do
|
36
|
+
{ :raw_info => raw_info }
|
37
|
+
end
|
38
|
+
|
39
|
+
def raw_info
|
40
|
+
@raw_info ||= customer_data
|
41
|
+
end
|
42
|
+
|
43
|
+
def callback_url
|
44
|
+
full_host + script_name + callback_path # + query_string
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def build_access_token
|
50
|
+
verifier = request.params['code']
|
51
|
+
calculated_secret = Digest::SHA1.hexdigest "#{options.client_id}#{options.client_secret}#{verifier}"
|
52
|
+
client = ::OAuth2::Client.new(options.client_id, calculated_secret, deep_symbolize(options.client_options))
|
53
|
+
client.auth_code.get_token(verifier,
|
54
|
+
{:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)),
|
55
|
+
deep_symbolize({header_format: "Bearer %s, Id #{options.client_id}"}))
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def customer_data
|
61
|
+
data = request_customer_data
|
62
|
+
if data['state'] == 'ok'
|
63
|
+
person = data['customer']
|
64
|
+
if person['type'] == 'physical'
|
65
|
+
decrypt_customer_data(person)
|
66
|
+
end
|
67
|
+
person
|
68
|
+
else
|
69
|
+
raise NoCustomerError.new(data.to_s)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def request_customer_data
|
74
|
+
access_token.post("#{options.data_site}/ResourceService/checked/data",
|
75
|
+
{
|
76
|
+
headers: {
|
77
|
+
'Content-Type' => "application/json",
|
78
|
+
'Accept' => "application/json"
|
79
|
+
},
|
80
|
+
body: customer_data_post_params.to_json
|
81
|
+
}
|
82
|
+
).parsed
|
83
|
+
rescue ::Errno::ETIMEDOUT
|
84
|
+
raise ::Timeout::Error
|
85
|
+
end
|
86
|
+
|
87
|
+
def decrypt_customer_data(person)
|
88
|
+
if person['signature'].present?
|
89
|
+
fields = ['inn', 'firstName', 'middleName', 'lastName', 'phone', 'email']
|
90
|
+
fields.each do |field_name|
|
91
|
+
begin
|
92
|
+
person[field_name] = decrypt(person[field_name])
|
93
|
+
rescue Exception => e
|
94
|
+
OmniAuth.config.logger.error("#{self.class} could not decrypt field: #{field_name}, because: #{e.message}")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def decrypt(field_value)
|
101
|
+
private_key.private_decrypt(Base64::decode64(field_value))
|
102
|
+
end
|
103
|
+
|
104
|
+
def private_key
|
105
|
+
@private_key ||= OpenSSL::PKey::RSA.new(File.read(options.private_key_path))
|
106
|
+
end
|
107
|
+
|
108
|
+
def customer_data_post_params
|
109
|
+
{
|
110
|
+
"type" => "physical",
|
111
|
+
"fields" => [
|
112
|
+
"firstName",
|
113
|
+
"middleName",
|
114
|
+
"lastName",
|
115
|
+
"phone",
|
116
|
+
"inn",
|
117
|
+
"clId",
|
118
|
+
"clIdText",
|
119
|
+
"birthDay",
|
120
|
+
"email",
|
121
|
+
"sex",
|
122
|
+
"resident",
|
123
|
+
"dateModification"
|
124
|
+
]
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class PrivatbankUaSandbox < OmniAuth::Strategies::PrivatbankUa
|
130
|
+
# for testing against their test servers,
|
131
|
+
# to test data decryption make sure you have the PrivatBank public/secret keys from production
|
132
|
+
SANDBOX_OAUTH_DOMAIN = 'https://bankid.privatbank.ua'
|
133
|
+
SANDBOX_DATA_DOMAIN = 'https://bankid.privatbank.ua'
|
134
|
+
default_options[:client_options][:site] = SANDBOX_OAUTH_DOMAIN
|
135
|
+
default_options[:data_site] = SANDBOX_DATA_DOMAIN
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
OmniAuth.config.add_camelization "privatbank-ua", "PrivatbankUa"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-privatbank-ua/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-privatbank-ua"
|
7
|
+
s.version = OmniAuth::PrivatbankUa::VERSION
|
8
|
+
s.authors = ["Aivils Stoss"]
|
9
|
+
s.email = ["aivils@ithouse.lv"]
|
10
|
+
s.homepage = "https://github.com/ithouse/omniauth-privatbank-ua"
|
11
|
+
s.summary = %q{OmniAuth strategy for privatbank.ua}
|
12
|
+
s.description = %q{OmniAuth strategy for privatbank.ua}
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency 'multi_json', '~> 1.3'
|
21
|
+
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.0'
|
22
|
+
s.add_development_dependency 'rspec', '~> 2.7'
|
23
|
+
s.add_development_dependency 'rack-test'
|
24
|
+
s.add_development_dependency 'simplecov'
|
25
|
+
s.add_development_dependency 'webmock'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-privatbank-ua
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aivils Stoss
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: OmniAuth strategy for privatbank.ua
|
98
|
+
email:
|
99
|
+
- aivils@ithouse.lv
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- Gemfile
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/omniauth-privatbank-ua.rb
|
108
|
+
- lib/omniauth-privatbank-ua/version.rb
|
109
|
+
- lib/omniauth/strategies/privatbank-ua.rb
|
110
|
+
- omniauth-privatbank-ua.gemspec
|
111
|
+
homepage: https://github.com/ithouse/omniauth-privatbank-ua
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.4.5
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: OmniAuth strategy for privatbank.ua
|
135
|
+
test_files: []
|