login_radius 1.0.1 → 11.0.0.pre.beta

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.
Files changed (36) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +21 -0
  3. data/README.md +58 -0
  4. data/lib/login_radius.rb +27 -9
  5. data/lib/login_radius/api/account/account_api.rb +581 -0
  6. data/lib/login_radius/api/account/role_api.rb +330 -0
  7. data/lib/login_radius/api/account/sott_api.rb +47 -0
  8. data/lib/login_radius/api/advanced/configuration_api.rb +57 -0
  9. data/lib/login_radius/api/advanced/consent_management_api.rb +161 -0
  10. data/lib/login_radius/api/advanced/custom_object_api.rb +316 -0
  11. data/lib/login_radius/api/advanced/custom_registration_data_api.rb +195 -0
  12. data/lib/login_radius/api/advanced/multi_factor_authentication_api.rb +606 -0
  13. data/lib/login_radius/api/advanced/re_authentication_api.rb +243 -0
  14. data/lib/login_radius/api/advanced/web_hook_api.rb +101 -0
  15. data/lib/login_radius/api/authentication/authentication_api.rb +989 -0
  16. data/lib/login_radius/api/authentication/one_touch_login_api.rb +160 -0
  17. data/lib/login_radius/api/authentication/password_less_login_api.rb +158 -0
  18. data/lib/login_radius/api/authentication/phone_authentication_api.rb +329 -0
  19. data/lib/login_radius/api/authentication/pin_authentication_api.rb +316 -0
  20. data/lib/login_radius/api/authentication/risk_based_authentication_api.rb +286 -0
  21. data/lib/login_radius/api/authentication/smart_login_api.rb +146 -0
  22. data/lib/login_radius/api/social/native_social_api.rb +255 -0
  23. data/lib/login_radius/api/social/social_api.rb +806 -0
  24. data/lib/login_radius/error.rb +7 -0
  25. data/lib/login_radius/request_client.rb +295 -0
  26. data/lib/login_radius/response.rb +12 -0
  27. data/lib/login_radius/version.rb +2 -2
  28. data/login_radius.gemspec +28 -0
  29. metadata +47 -30
  30. data/lib/hash.rb +0 -13
  31. data/lib/login_radius/exception.rb +0 -4
  32. data/lib/login_radius/messages.rb +0 -41
  33. data/lib/login_radius/related.rb +0 -34
  34. data/lib/login_radius/user_profile.rb +0 -101
  35. data/lib/login_radius/user_profile_getters.rb +0 -152
  36. data/lib/string.rb +0 -8
@@ -0,0 +1,7 @@
1
+ module LoginRadius
2
+ class Error < StandardError
3
+ def initialize(msg = 'An error occurred.')
4
+ super(msg)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,295 @@
1
+ require 'net/http'
2
+ require 'openssl'
3
+ require 'base64'
4
+ require 'cgi'
5
+
6
+ module LoginRadius
7
+ module RequestClient
8
+ # LoginRadius Client Module: Methods relating to building and sending requests are defined here.
9
+
10
+ API_V2_BASE_URL = 'https://api.loginradius.com/'
11
+ API_V2_BASE_URL_CONFIG = 'https://config.lrcontent.com/'
12
+ INIT_VECTOR = 'tu89geji340t89u2'
13
+ KEY_SIZE = 256
14
+
15
+ # Sends a POST API request.
16
+ #
17
+ # @param uri_endpoint [URI] Target uri instance
18
+ # @param params [Hash] Parameters to send
19
+ # @param body [Hash] POST body
20
+ #
21
+ # @return [LoginRadius::Response] LoginRadius response instance
22
+ def post_request(uri_endpoint, params, body = {})
23
+ uri_obj = build_new_uri_obj(uri_endpoint)
24
+
25
+ headers = { 'Content-Type' => 'application/json' }
26
+ if params.key?('access_token') # has_key
27
+ if uri_endpoint.include? 'auth'
28
+ access_token = params['access_token']
29
+ params.delete('access_token')
30
+ headers['Authorization'] = 'Bearer ' + access_token
31
+ end
32
+ end
33
+
34
+ if params.key?('apiSecret') # has_key
35
+ secret_key = params['apiSecret']
36
+ params.delete('apiSecret')
37
+
38
+ if ENV['API_REQUEST_SIGNING'] == 'false' || ENV['API_REQUEST_SIGNING'] == nil
39
+ headers['X-LoginRadius-ApiSecret'] = secret_key
40
+ else
41
+ uri_obj = build_new_uri_obj(uri_endpoint)
42
+ uri_obj.query = URI.encode_www_form(params)
43
+ headers = create_hash_secret(uri_obj.request_uri, secret_key, headers, body)
44
+ end
45
+ end
46
+ if params.key?('sott') # has_key
47
+ headers['X-LoginRadius-Sott'] = params['sott']
48
+ params.delete('sott')
49
+ end
50
+
51
+ uri_obj.query = URI.encode_www_form(params)
52
+ http = Net::HTTP.new(uri_obj.host, uri_obj.port)
53
+ http.use_ssl = true
54
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
55
+
56
+ response = http.post(uri_obj.request_uri, body.to_json, headers)
57
+
58
+ begin
59
+ return LoginRadius::Response.new(response)
60
+ rescue JSON::ParserError => e
61
+ raise LoginRadius::Error.new("JSON parsing error has occurred. More info: #{e.message}")
62
+ end
63
+ end
64
+
65
+ def isNullOrWhiteSpace(params)
66
+ return params.blank? ? true : false
67
+ end
68
+
69
+ def getValidationMessage(params)
70
+ return params + " is a required parameter."
71
+ end
72
+
73
+ # Sends a GET API request.
74
+ #
75
+ # @param uri_endpoint [URI] Target uri instance
76
+ # @param params [Hash] Parameters to send
77
+ # @param body [Hash] Request body
78
+ #
79
+ # @return [LoginRadius::Response] LoginRadius response instance
80
+ def get_request(uri_endpoint, params, body = {})
81
+ uri_obj = build_new_uri_obj(uri_endpoint)
82
+
83
+ headers = {'Content-Type' => 'application/json'}
84
+ if params.key?('access_token') # has_key
85
+ if uri_endpoint.include? 'auth'
86
+ access_token = params['access_token']
87
+ params.delete('access_token')
88
+ headers['Authorization'] = 'Bearer ' + access_token
89
+ end
90
+ end
91
+
92
+ if params.key?('apiSecret') # has_key
93
+ secret_key = params['apiSecret']
94
+ params.delete('apiSecret')
95
+
96
+ if ENV['API_REQUEST_SIGNING'] == 'false' || ENV['API_REQUEST_SIGNING'] == nil
97
+ headers['X-LoginRadius-ApiSecret'] = secret_key
98
+ else
99
+ uri_obj = build_new_uri_obj(uri_endpoint)
100
+ uri_obj.query = URI.encode_www_form(params)
101
+ headers = create_hash_secret(uri_obj.request_uri, secret_key, headers, body)
102
+ end
103
+ end
104
+ if params.key?('sott') # has_key
105
+ headers['X-LoginRadius-Sott'] = params['sott']
106
+ params.delete('sott')
107
+ end
108
+
109
+ uri_obj.query = URI.encode_www_form(params)
110
+ http = Net::HTTP.new(uri_obj.host, uri_obj.port)
111
+ http.use_ssl = true
112
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
113
+ response = http.get(uri_obj.request_uri, headers)
114
+
115
+ begin
116
+ return LoginRadius::Response.new(response)
117
+ rescue JSON::ParserError => e
118
+ raise LoginRadius::Error.new("JSON parsing error has occurred. More info: #{e.message}")
119
+ end
120
+ end
121
+
122
+ # Sends a PUT API request.
123
+ #
124
+ # @param uri_endpoint [URI] Target uri instance
125
+ # @param params [Hash] Parameters to send
126
+ # @param body [Hash] PUT body
127
+ #
128
+ # @return [LoginRadius::Response] LoginRadius response instance
129
+ def put_request(uri_endpoint, params, body = {})
130
+ uri_obj = build_new_uri_obj(uri_endpoint)
131
+
132
+ headers = { 'Content-Type' => 'application/json' }
133
+ if params.key?('access_token') # has_key
134
+ if uri_endpoint.include? 'auth'
135
+ access_token = params['access_token']
136
+ params.delete('access_token')
137
+ headers['Authorization'] = 'Bearer ' + access_token
138
+ end
139
+ end
140
+
141
+ if params.key?('apiSecret') # has_key
142
+ secret_key = params['apiSecret']
143
+ params.delete('apiSecret')
144
+
145
+ if ENV['API_REQUEST_SIGNING'] == 'false' || ENV['API_REQUEST_SIGNING'] == nil
146
+ headers['X-LoginRadius-ApiSecret'] = secret_key
147
+ else
148
+ uri_obj = build_new_uri_obj(uri_endpoint)
149
+ uri_obj.query = URI.encode_www_form(params)
150
+
151
+ headers = create_hash_secret(uri_obj.request_uri, secret_key, headers, body)
152
+ end
153
+ end
154
+ if params.key?('sott') # has_key
155
+ headers['X-LoginRadius-Sott'] = params['sott']
156
+ params.delete('sott')
157
+ end
158
+
159
+ uri_obj.query = URI.encode_www_form(params)
160
+ http = Net::HTTP.new(uri_obj.host, uri_obj.port)
161
+ http.use_ssl = true
162
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
163
+ response = http.put(uri_obj.request_uri, body.to_json, headers)
164
+ begin
165
+ return LoginRadius::Response.new(response)
166
+ rescue JSON::ParserError => e
167
+ raise LoginRadius::Error.new("JSON parsing error has occurred. More info: #{e.message}")
168
+ end
169
+ end
170
+
171
+ # Sends a DELETE API request.
172
+ #
173
+ # @param uri_endpoint [URI] Target uri instance
174
+ # @param params [Hash] Parameters to send
175
+ # @param body [Hash] POST body
176
+ #
177
+ # @return [LoginRadius::Response] LoginRadius response instance
178
+ def delete_request(uri_endpoint, params, body = {})
179
+ uri_obj = build_new_uri_obj(uri_endpoint)
180
+
181
+ headers = { 'Content-Type' => 'application/json' }
182
+ if params.key?('access_token') # has_key
183
+ if uri_endpoint.include? 'auth'
184
+ access_token = params['access_token']
185
+ params.delete('access_token')
186
+ headers['Authorization'] = 'Bearer ' + access_token
187
+ end
188
+ end
189
+
190
+ if params.key?('apiSecret') # has_key
191
+ secret_key = params['apiSecret']
192
+ params.delete('apiSecret')
193
+
194
+ if ENV['API_REQUEST_SIGNING'] == 'false' || ENV['API_REQUEST_SIGNING'] == nil
195
+ headers['X-LoginRadius-ApiSecret'] = secret_key
196
+ else
197
+ uri_obj = build_new_uri_obj(uri_endpoint)
198
+ uri_obj.query = URI.encode_www_form(params)
199
+ headers = create_hash_secret(uri_obj.request_uri, secret_key, headers, body)
200
+ end
201
+ end
202
+ if params.key?('sott') # has_key
203
+ headers['X-LoginRadius-Sott'] = params['sott']
204
+ params.delete('sott')
205
+ end
206
+
207
+ uri_obj.query = URI.encode_www_form(params)
208
+ http = Net::HTTP.new(uri_obj.host, uri_obj.port)
209
+ http.use_ssl = true
210
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
211
+ req = Net::HTTP::Delete.new(uri_obj.request_uri, headers)
212
+ req.body = body.to_json
213
+ response = http.request(req)
214
+
215
+ begin
216
+ return LoginRadius::Response.new(response)
217
+ rescue JSON::ParserError => e
218
+ raise LoginRadius::Error.new("JSON parsing error has occurred. More info: #{e.message}")
219
+ end
220
+ end
221
+
222
+ # Builds a URI instance given type and resource
223
+ #
224
+ # @param resource [String] Target resource
225
+ # custom_api_domain is set
226
+ # @return [URI] uri instance
227
+ def build_new_uri_obj(resource)
228
+ if resource == 'ciam/appinfo'
229
+ return URI.parse(API_V2_BASE_URL_CONFIG + resource)
230
+ else
231
+ if ENV['CUSTOM_API_DOMAIN'] == 'false' || ENV['CUSTOM_API_DOMAIN'] == nil
232
+ return URI.parse(API_V2_BASE_URL + resource)
233
+ else
234
+ return URI.parse(ENV['CUSTOM_API_DOMAIN'] + resource)
235
+ end
236
+ end
237
+ end
238
+
239
+ # Create a has digest in header
240
+ #
241
+ # @param endpoint [String] endpoint
242
+ # @param secret_key [String] secret key
243
+ # @param headers [String] headers
244
+ # @param body [String] body
245
+ # @return [URI] uri instance
246
+ #
247
+ # @return [headers] header
248
+ def create_hash_secret(endpoint, secret_key, headers, body = {})
249
+ endpoint_uri = 'https://api.loginradius.com' + endpoint
250
+ expiry_time = (Time.now.getutc() + (1*60*60)).strftime('%Y/%m/%d %H:%M:%S')
251
+
252
+ encoded_uri = CGI.escape(CGI.unescape(endpoint_uri))
253
+
254
+ if body.blank?
255
+ string_to_hash = expiry_time + ':' + encoded_uri.downcase
256
+ else
257
+ string_to_hash = expiry_time + ':' + encoded_uri.downcase + ':' + body.to_json
258
+ end
259
+
260
+ mac = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), secret_key, string_to_hash)).strip()
261
+ headers['X-Request-Expires'] = expiry_time
262
+ headers['digest'] = 'SHA-256='+mac
263
+ return headers
264
+ end
265
+
266
+ # Local - Generate SOTT:
267
+ # Generates a Secured One Time Token locally.
268
+ #
269
+ # @params validity_length [Integer] Length of time the SOTT is valid for in minutes
270
+ #
271
+ # @returns sott [String] LoginRadius Secured One Time Token
272
+ def local_generate_sott(validity_length = 10)
273
+ start_time = Time.now.getutc().strftime('%Y/%m/%d %H:%M:%S')
274
+ end_time = (Time.now.getutc() + (validity_length*60)).strftime('%Y/%m/%d %H:%M:%S')
275
+
276
+ plain_text = start_time + '#' + ENV['API_KEY'] + '#' + end_time
277
+ iter = 10000
278
+ salt = "\x00\x00\x00\x00\x00\x00\x00\x00"
279
+ key_len = KEY_SIZE / 8
280
+ cipher_key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(ENV['API_SECRET'], salt, iter, key_len)
281
+
282
+ cipher = OpenSSL::Cipher.new('aes-' + KEY_SIZE.to_s + '-cbc')
283
+ cipher.encrypt
284
+ cipher.key = cipher_key
285
+ cipher.iv = INIT_VECTOR
286
+
287
+ encrypted = cipher.update(plain_text) + cipher.final
288
+ encrypted_b64 = Base64.strict_encode64(encrypted)
289
+
290
+ hash = Digest::MD5.hexdigest(encrypted_b64)
291
+ sott = encrypted_b64 + '*' + hash
292
+ return sott
293
+ end
294
+ end
295
+ end
@@ -0,0 +1,12 @@
1
+ module LoginRadius
2
+ class Response
3
+ # LoginRadius Response Class: Defines the data response object returned from an API call.
4
+
5
+ attr_accessor :code, :body
6
+
7
+ def initialize(response)
8
+ self.code = response.code
9
+ self.body = JSON.parse(response.body, :symbolize_names => true)
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module LoginRadius
2
- VERSION = "1.0.1"
3
- end
2
+ VERSION = "11.0.0-beta"
3
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "login_radius/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "login_radius"
8
+ spec.version = LoginRadius::VERSION
9
+ spec.authors = ["LoginRadius"]
10
+ spec.email = ["developers@loginradius.com"]
11
+
12
+ spec.summary = %q{A Ruby wrapper for the LoginRadius API.}
13
+ spec.homepage = "https://www.loginradius.com"
14
+ spec.license = "MIT"
15
+
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata CHANGED
@@ -1,59 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: login_radius
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 11.0.0.pre.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - LoginRadius
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: em-http-request
14
+ name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
19
+ version: '1.16'
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.16'
27
27
  - !ruby/object:Gem::Dependency
28
- name: em-synchrony
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
33
+ version: '10.0'
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
41
- description: Ruby wrapper for LoginRadius API v2
40
+ version: '10.0'
41
+ description:
42
42
  email:
43
- - hello@loginradius.com
43
+ - developers@loginradius.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - lib/hash.rb
48
+ - LICENSE.txt
49
+ - README.md
49
50
  - lib/login_radius.rb
50
- - lib/string.rb
51
- - lib/login_radius/exception.rb
52
- - lib/login_radius/messages.rb
53
- - lib/login_radius/related.rb
54
- - lib/login_radius/user_profile.rb
55
- - lib/login_radius/user_profile_getters.rb
51
+ - lib/login_radius/api/account/account_api.rb
52
+ - lib/login_radius/api/account/role_api.rb
53
+ - lib/login_radius/api/account/sott_api.rb
54
+ - lib/login_radius/api/advanced/configuration_api.rb
55
+ - lib/login_radius/api/advanced/consent_management_api.rb
56
+ - lib/login_radius/api/advanced/custom_object_api.rb
57
+ - lib/login_radius/api/advanced/custom_registration_data_api.rb
58
+ - lib/login_radius/api/advanced/multi_factor_authentication_api.rb
59
+ - lib/login_radius/api/advanced/re_authentication_api.rb
60
+ - lib/login_radius/api/advanced/web_hook_api.rb
61
+ - lib/login_radius/api/authentication/authentication_api.rb
62
+ - lib/login_radius/api/authentication/one_touch_login_api.rb
63
+ - lib/login_radius/api/authentication/password_less_login_api.rb
64
+ - lib/login_radius/api/authentication/phone_authentication_api.rb
65
+ - lib/login_radius/api/authentication/pin_authentication_api.rb
66
+ - lib/login_radius/api/authentication/risk_based_authentication_api.rb
67
+ - lib/login_radius/api/authentication/smart_login_api.rb
68
+ - lib/login_radius/api/social/native_social_api.rb
69
+ - lib/login_radius/api/social/social_api.rb
70
+ - lib/login_radius/error.rb
71
+ - lib/login_radius/request_client.rb
72
+ - lib/login_radius/response.rb
56
73
  - lib/login_radius/version.rb
74
+ - login_radius.gemspec
57
75
  homepage: https://www.loginradius.com
58
76
  licenses:
59
77
  - MIT
@@ -64,18 +82,17 @@ require_paths:
64
82
  - lib
65
83
  required_ruby_version: !ruby/object:Gem::Requirement
66
84
  requirements:
67
- - - '>='
85
+ - - ">="
68
86
  - !ruby/object:Gem::Version
69
87
  version: '0'
70
88
  required_rubygems_version: !ruby/object:Gem::Requirement
71
89
  requirements:
72
- - - '>='
90
+ - - ">"
73
91
  - !ruby/object:Gem::Version
74
- version: '0'
92
+ version: 1.3.1
75
93
  requirements: []
76
- rubyforge_project:
77
- rubygems_version: 2.0.14
94
+ rubygems_version: 3.0.3
78
95
  signing_key:
79
96
  specification_version: 4
80
- summary: Is a ruby wrapper for LoginRadius API v2
97
+ summary: A Ruby wrapper for the LoginRadius API.
81
98
  test_files: []