omniauth-sberbusiness 1.0.0 → 1.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 937ea6016cb610ed9d296dc0f5f4938198c8b4ca192a1b29c53f5e1d208315af
4
- data.tar.gz: ef2882ea928b375ef21196f8d0a6fb628d95a005b385dc2f72e55097173144bc
3
+ metadata.gz: fc6a24d6b570f4a4ee525fca24fb894a5a3bd732be93b89b15d21c01c8442e3c
4
+ data.tar.gz: 3557c296ec5f0b6b7fb08866f84565e5664bac34244bc77306f32fa41c71292a
5
5
  SHA512:
6
- metadata.gz: cbc8e94db10462e42bffef58a0758eb9dbabf9a681faf56b0db9d782984bbc05974ddc50e64621acba339075e557a80eca1b7115983d4e28a1e375057bf43724
7
- data.tar.gz: 647b58e4b718efcbd2fd3f32a45f99ab3cf2a28aa49b4bd8eae7fb29720a5ea13934cf4583b7f8189ffd55a8f621583dee83446cb373e4f5f645bd88f3db1744
6
+ metadata.gz: b720db90f54c0ef88124077f3681a0de7430ebe591a9429fb3bbf930ad2410014069d0968dd908885b8313cdbf456775425468ca08f9c20dc67403e20493a882
7
+ data.tar.gz: e9baea1e868b23932099630ae310af10ed9b197498b77aab832941974715e50a3135d717212576b70f3336c5b519d2af5f95a996435e5421900e93eb5dbe24a3
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  coverage
4
4
  Gemfile.lock
5
5
  .idea
6
+ *.gem
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module Sberbusiness
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.4'
6
6
  end
7
7
  end
@@ -6,6 +6,7 @@ require 'base64'
6
6
 
7
7
  module OmniAuth
8
8
  module Strategies
9
+ # https://developer.sberbank.ru/doc/v3/sbbol
9
10
  class Sberbusiness < OmniAuth::Strategies::OAuth2
10
11
  class NoRawData < StandardError; end
11
12
 
@@ -15,11 +16,14 @@ module OmniAuth
15
16
 
16
17
  option :name, 'sberbusiness'
17
18
 
19
+ option :test, false
20
+
18
21
  option :client_options,
19
- site: 'https://edupirfintech.sberbank.ru:9443', # 'https://edupir.testsbi.sberbank.ru:9443', # 'https://sbi.sberbank.ru:9443',
20
- token_url: 'https://edupirfintech.sberbank.ru:9443/ic/sso/api/v2/oauth/token', # https://edupirfintech.sberbank.ru:9443 https://sbi.sberbank.ru:9443/ic/sso/api/v2/oauth/token
21
- authorize_url: 'https://edupir.testsbi.sberbank.ru:9443/ic/sso/api/v2/oauth/authorize'
22
- # 'https://edupir.testsbi.sberbank.ru:9443/ic/sso/api/v2/oauth/authorize' # 'https://sbi.sberbank.ru:9443/ic/sso/api/v2/oauth/authorize'
22
+ site: 'https://fintech.sberbank.ru:9443',
23
+ token_url: 'https://fintech.sberbank.ru:9443/ic/sso/api/v2/oauth/token',
24
+ authorize_url: 'https://sbi.sberbank.ru:9443/ic/sso/api/v2/oauth/authorize',
25
+ user_info_path: '/ic/sso/api/v2/oauth/user-info',
26
+ client_info_path: '/api/v1/client-info'
23
27
 
24
28
  option :authorize_options, %i[scope response_type client_type client_id state nonce]
25
29
 
@@ -42,32 +46,40 @@ module OmniAuth
42
46
  accounts: raw_info['accounts'],
43
47
  id: raw_info['sub'],
44
48
  inn: raw_info['inn'],
45
- client_host: raw_info['state'],
46
- provider: 'sberbusiness'
49
+ provider: options.name
47
50
  }
48
51
  end
49
52
 
50
53
  extra do
51
- {
52
- 'raw_info' => raw_info
53
- }
54
+ if options.test
55
+ {
56
+ 'raw_info' => raw_info,
57
+ 'credentials' => credentials
58
+ }
59
+ else
60
+ { 'raw_info' => raw_info }
61
+ end
54
62
  end
55
63
 
56
- # https://developer.sberbank.ru/doc/v1/sberbank-id/datareq
57
64
  def raw_info
58
65
  access_token.options[:mode] = :header
59
66
  @raw_info ||= begin
60
- state = request.params['state']
61
- result = access_token.get('/ic/sso/api/v2/oauth/user-info', headers: info_headers).body
67
+ result = access_token.get(options.client_options['user_info_path'], headers: info_headers).body
62
68
  # декодируем ответ:
63
- decoded_data = result.split('.').map { |code| JSON.parse(Base64.decode64(code)) rescue {}}
69
+ decoded_data = result.split('.').map { |code| decrypt(code) rescue {}}
64
70
  result = decoded_data.reduce(:merge)
65
- result['state'] = state
66
- result
71
+ # здесь нужен скоп специальный, а на тесте мы его задать не можем
72
+ return result unless options.test
73
+
74
+ org_info = access_token.get(options.client_options['client_info_path'], headers: info_headers).body
75
+ result.merge({ client_info: org_info.force_encoding('UTF-8') })
67
76
  end
68
77
  end
69
78
 
70
- # https://developer.sberbank.ru/doc/v1/sberbank-id/authcodereq
79
+ def decrypt(msg)
80
+ JSON.parse(Base64.urlsafe_decode64(msg).force_encoding(Encoding::UTF_8))
81
+ end
82
+
71
83
  def authorize_params
72
84
  super.tap do |params|
73
85
  %w[state scope response_type client_type client_id nonce].each do |v|
@@ -76,10 +88,6 @@ module OmniAuth
76
88
  params[v.to_sym] = request.params[v]
77
89
  end
78
90
  params[:scope] ||= DEFAULT_SCOPE
79
- # if you want redirect to other host and save old host
80
- state = session['omniauth.origin'] || env['HTTP_REFERER']
81
- params[:state] = state
82
- session['omniauth.state'] = state
83
91
  params[:nonce] = SecureRandom.hex(16)
84
92
  end
85
93
  end
@@ -100,7 +108,6 @@ module OmniAuth
100
108
  end
101
109
 
102
110
  def info_options
103
- # https://developer.sberbank.ru/doc/v1/sberbank-id/dataanswerparametrs
104
111
  fields = %w[
105
112
  sub family_name given_name middle_name birthdate email phone_number
106
113
  address_reg identification inn snils gender
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-sberbusiness
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Baksheev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-16 00:00:00.000000000 Z
11
+ date: 2021-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2
@@ -45,6 +45,8 @@ files:
45
45
  - lib/omniauth-sberbusiness.rb
46
46
  - lib/omniauth/sberbusiness/version.rb
47
47
  - lib/omniauth/strategies/sberbusiness.rb
48
+ - omniauth-sberbusiness-1.0.0.gem
49
+ - omniauth-sberbusiness-1.0.2.gem
48
50
  - omniauth-sberbusiness.gemspec
49
51
  homepage: https://github.com/insales/omniauth-sberbusiness
50
52
  licenses:
@@ -65,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
67
  - !ruby/object:Gem::Version
66
68
  version: '0'
67
69
  requirements: []
68
- rubygems_version: 3.2.19
70
+ rubygems_version: 3.1.2
69
71
  signing_key:
70
72
  specification_version: 4
71
73
  summary: Sberbusiness OAuth2 Strategy for OmniAuth