ipizza-omniauth-provider 0.1.5 → 0.2.0

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.
@@ -1,7 +1,7 @@
1
1
  module Ipizza
2
2
  module Omniauth
3
3
  module Provider
4
- VERSION = '0.1.5'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
  end
7
7
  end
@@ -19,26 +19,30 @@ module OmniAuth
19
19
  end
20
20
 
21
21
  def request_phase
22
- if env['REQUEST_METHOD'] == 'GET'
23
- get_credentials
24
- else
22
+ if request.params['bank']
25
23
  provider = ipizza_provider_for(request.params['bank'])
26
-
27
- req = provider.authentication_request
28
- url = [req.service_url, Rack::Utils.build_query(req.request_params)] * '?'
29
-
30
- debug "Redirecting to #{url}"
31
24
 
32
- redirect url
25
+ if provider
26
+ begin
27
+ req = provider.authentication_request
28
+
29
+ url = [req.service_url, Rack::Utils.build_query(req.request_params)] * '?'
30
+
31
+ debug "Redirecting to #{url}"
32
+
33
+ redirect url
34
+ rescue => e
35
+ debug "Failed to create provider rquest: #{e.inspect}"
36
+ fail!(:internal_error, {'ipizza_error' => 'internal_error', 'message' => "Failed to create request for provider '#{request.params['bank']}'."})
37
+ end
38
+ else
39
+ fail!(:invalid_ipizza_provider, {'ipizza_error' => 'invalid_ipizza_provider', 'message' => "Invalid Ipizza provider '#{request.params['bank']}'"})
40
+ end
41
+ else
42
+ fail!(:bank_identifier_missing, {'ipizza_error' => 'bank_identifier_missing', 'message' => 'Bank identifier is missing'})
33
43
  end
34
44
  end
35
45
 
36
- def get_credentials
37
- OmniAuth::Form.build(@title) do
38
- text_field 'Bank', 'bank'
39
- end.to_response
40
- end
41
-
42
46
  def callback_phase
43
47
  debug "Callback in iPizza authentication. Parameters: #{request.params.inspect}"
44
48
 
@@ -49,22 +53,27 @@ module OmniAuth
49
53
 
50
54
  if request.params['VK_SND_ID']
51
55
  provider = ipizza_provider_for(request.params['VK_SND_ID'])
52
- resp = provider.authentication_response(request.params)
56
+
57
+ if provider
58
+ resp = provider.authentication_response(request.params)
53
59
 
54
- if resp.valid? and resp.success?
55
- @user_data = {'personal_code' => resp.info_social_security_id, 'name' => resp.info_name}
56
- @env['omniauth.auth'] = auth_hash
60
+ if resp.valid? and resp.success?
61
+ @user_data = {'personal_code' => resp.info_social_security_id, 'name' => resp.info_name}
62
+ @env['omniauth.auth'] = auth_hash
57
63
 
58
- debug "iPizza request was authenticated successfully. User data: #{auth_hash.inspect}"
64
+ debug "iPizza request was authenticated successfully. User data: #{auth_hash.inspect}"
59
65
 
60
- call_app!
66
+ call_app!
67
+ else
68
+ debug 'Could not authenticate iPizza request'
69
+ fail!(:invalid_credentials, {'ipizza_error' => 'invalid_credentials', 'message' => 'Invalid bank response'})
70
+ end
61
71
  else
62
- debug 'Could not authenticate iPizza request'
63
- fail!(:invalid_credentials, {'error' => 'Invalid bank response'})
72
+ fail!(:invalid_ipizza_provider, {'ipizza_error' => 'invalid_ipizza_provider', 'message' => "Invalid Ipizza provider '#{request.params['VK_SND_ID']}'"})
64
73
  end
65
74
  else
66
75
  debug 'Did not recognize iPizza request'
67
- fail(:invalid_credentials, {'error' => 'Bank request cancelled'})
76
+ fail!(:invalid_credentials, {'ipizza_error' => 'invalid_credentials', 'message' => 'Bank request cancelled'})
68
77
  end
69
78
  end
70
79
 
@@ -101,4 +110,4 @@ module OmniAuth
101
110
 
102
111
  end
103
112
  end
104
- end
113
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipizza-omniauth-provider
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 5
10
- version: 0.1.5
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Priit Haamer