login_radius 11.0.0 → 11.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +58 -58
- data/lib/login_radius/api/account/account_api.rb +581 -581
- data/lib/login_radius/api/account/role_api.rb +330 -330
- data/lib/login_radius/api/account/sott_api.rb +47 -47
- data/lib/login_radius/api/advanced/configuration_api.rb +57 -57
- data/lib/login_radius/api/advanced/consent_management_api.rb +161 -161
- data/lib/login_radius/api/advanced/custom_object_api.rb +316 -316
- data/lib/login_radius/api/advanced/custom_registration_data_api.rb +195 -195
- data/lib/login_radius/api/advanced/multi_factor_authentication_api.rb +942 -606
- data/lib/login_radius/api/advanced/re_authentication_api.rb +317 -243
- data/lib/login_radius/api/advanced/web_hook_api.rb +101 -101
- data/lib/login_radius/api/authentication/authentication_api.rb +1036 -989
- data/lib/login_radius/api/authentication/one_touch_login_api.rb +160 -160
- data/lib/login_radius/api/authentication/password_less_login_api.rb +202 -158
- data/lib/login_radius/api/authentication/phone_authentication_api.rb +329 -329
- data/lib/login_radius/api/authentication/pin_authentication_api.rb +316 -316
- data/lib/login_radius/api/authentication/risk_based_authentication_api.rb +286 -286
- data/lib/login_radius/api/authentication/smart_login_api.rb +146 -146
- data/lib/login_radius/api/social/native_social_api.rb +255 -255
- data/lib/login_radius/api/social/social_api.rb +784 -806
- data/lib/login_radius/error.rb +7 -7
- data/lib/login_radius/request_client.rb +311 -295
- data/lib/login_radius/response.rb +18 -12
- data/lib/login_radius/version.rb +2 -2
- data/lib/login_radius.rb +30 -30
- data/login_radius.gemspec +25 -28
- metadata +7 -7
data/lib/login_radius/error.rb
CHANGED
@@ -1,7 +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
|
1
|
+
module LoginRadius
|
2
|
+
class Error < StandardError
|
3
|
+
def initialize(msg = 'An error occurred.')
|
4
|
+
super(msg)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
@@ -1,295 +1,311 @@
|
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
def
|
70
|
-
return params
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
#
|
78
|
-
#
|
79
|
-
# @
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
headers =
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
if params.key?('
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
if params.key?('
|
203
|
-
|
204
|
-
params.delete('
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
#
|
240
|
-
#
|
241
|
-
#
|
242
|
-
# @
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
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
|
+
unless ENV['Origin_IP'] == "" || ENV['Origin_IP'] == nil
|
52
|
+
headers['X-Origin-IP'] = ENV['Origin_IP']
|
53
|
+
end
|
54
|
+
|
55
|
+
uri_obj.query = URI.encode_www_form(params)
|
56
|
+
http = Net::HTTP.new(uri_obj.host, uri_obj.port)
|
57
|
+
http.use_ssl = true
|
58
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
59
|
+
|
60
|
+
response = http.post(uri_obj.request_uri, body.to_json, headers)
|
61
|
+
|
62
|
+
begin
|
63
|
+
return LoginRadius::Response.new(response)
|
64
|
+
rescue JSON::ParserError => e
|
65
|
+
raise LoginRadius::Error.new("JSON parsing error has occurred. More info: #{e.message}")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def isNullOrWhiteSpace(params)
|
70
|
+
return params.blank? ? true : false
|
71
|
+
end
|
72
|
+
|
73
|
+
def getValidationMessage(params)
|
74
|
+
return params + " is a required parameter."
|
75
|
+
end
|
76
|
+
|
77
|
+
# Sends a GET API request.
|
78
|
+
#
|
79
|
+
# @param uri_endpoint [URI] Target uri instance
|
80
|
+
# @param params [Hash] Parameters to send
|
81
|
+
# @param body [Hash] Request body
|
82
|
+
#
|
83
|
+
# @return [LoginRadius::Response] LoginRadius response instance
|
84
|
+
def get_request(uri_endpoint, params, body = {})
|
85
|
+
uri_obj = build_new_uri_obj(uri_endpoint)
|
86
|
+
|
87
|
+
headers = {'Content-Type' => 'application/json'}
|
88
|
+
if params.key?('access_token') # has_key
|
89
|
+
if uri_endpoint.include? 'auth'
|
90
|
+
access_token = params['access_token']
|
91
|
+
params.delete('access_token')
|
92
|
+
headers['Authorization'] = 'Bearer ' + access_token
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
if params.key?('apiSecret') # has_key
|
97
|
+
secret_key = params['apiSecret']
|
98
|
+
params.delete('apiSecret')
|
99
|
+
|
100
|
+
if ENV['API_REQUEST_SIGNING'] == 'false' || ENV['API_REQUEST_SIGNING'] == nil
|
101
|
+
headers['X-LoginRadius-ApiSecret'] = secret_key
|
102
|
+
else
|
103
|
+
uri_obj = build_new_uri_obj(uri_endpoint)
|
104
|
+
uri_obj.query = URI.encode_www_form(params)
|
105
|
+
headers = create_hash_secret(uri_obj.request_uri, secret_key, headers, body)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
if params.key?('sott') # has_key
|
109
|
+
headers['X-LoginRadius-Sott'] = params['sott']
|
110
|
+
params.delete('sott')
|
111
|
+
end
|
112
|
+
|
113
|
+
unless ENV['Origin_IP'] == "" || ENV['Origin_IP'] == nil
|
114
|
+
headers['X-Origin-IP'] = ENV['Origin_IP']
|
115
|
+
end
|
116
|
+
|
117
|
+
uri_obj.query = URI.encode_www_form(params)
|
118
|
+
http = Net::HTTP.new(uri_obj.host, uri_obj.port)
|
119
|
+
http.use_ssl = true
|
120
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
121
|
+
response = http.get(uri_obj.request_uri, headers)
|
122
|
+
|
123
|
+
begin
|
124
|
+
return LoginRadius::Response.new(response)
|
125
|
+
rescue JSON::ParserError => e
|
126
|
+
raise LoginRadius::Error.new("JSON parsing error has occurred. More info: #{e.message}")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Sends a PUT API request.
|
131
|
+
#
|
132
|
+
# @param uri_endpoint [URI] Target uri instance
|
133
|
+
# @param params [Hash] Parameters to send
|
134
|
+
# @param body [Hash] PUT body
|
135
|
+
#
|
136
|
+
# @return [LoginRadius::Response] LoginRadius response instance
|
137
|
+
def put_request(uri_endpoint, params, body = {})
|
138
|
+
uri_obj = build_new_uri_obj(uri_endpoint)
|
139
|
+
|
140
|
+
headers = { 'Content-Type' => 'application/json' }
|
141
|
+
if params.key?('access_token') # has_key
|
142
|
+
if uri_endpoint.include? 'auth'
|
143
|
+
access_token = params['access_token']
|
144
|
+
params.delete('access_token')
|
145
|
+
headers['Authorization'] = 'Bearer ' + access_token
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
if params.key?('apiSecret') # has_key
|
150
|
+
secret_key = params['apiSecret']
|
151
|
+
params.delete('apiSecret')
|
152
|
+
|
153
|
+
if ENV['API_REQUEST_SIGNING'] == 'false' || ENV['API_REQUEST_SIGNING'] == nil
|
154
|
+
headers['X-LoginRadius-ApiSecret'] = secret_key
|
155
|
+
else
|
156
|
+
uri_obj = build_new_uri_obj(uri_endpoint)
|
157
|
+
uri_obj.query = URI.encode_www_form(params)
|
158
|
+
|
159
|
+
headers = create_hash_secret(uri_obj.request_uri, secret_key, headers, body)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
if params.key?('sott') # has_key
|
163
|
+
headers['X-LoginRadius-Sott'] = params['sott']
|
164
|
+
params.delete('sott')
|
165
|
+
end
|
166
|
+
|
167
|
+
unless ENV['Origin_IP'] == "" || ENV['Origin_IP'] == nil
|
168
|
+
headers['X-Origin-IP'] = ENV['Origin_IP']
|
169
|
+
end
|
170
|
+
|
171
|
+
uri_obj.query = URI.encode_www_form(params)
|
172
|
+
http = Net::HTTP.new(uri_obj.host, uri_obj.port)
|
173
|
+
http.use_ssl = true
|
174
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
175
|
+
response = http.put(uri_obj.request_uri, body.to_json, headers)
|
176
|
+
begin
|
177
|
+
return LoginRadius::Response.new(response)
|
178
|
+
rescue JSON::ParserError => e
|
179
|
+
raise LoginRadius::Error.new("JSON parsing error has occurred. More info: #{e.message}")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Sends a DELETE API request.
|
184
|
+
#
|
185
|
+
# @param uri_endpoint [URI] Target uri instance
|
186
|
+
# @param params [Hash] Parameters to send
|
187
|
+
# @param body [Hash] POST body
|
188
|
+
#
|
189
|
+
# @return [LoginRadius::Response] LoginRadius response instance
|
190
|
+
def delete_request(uri_endpoint, params, body = {})
|
191
|
+
uri_obj = build_new_uri_obj(uri_endpoint)
|
192
|
+
|
193
|
+
headers = { 'Content-Type' => 'application/json' }
|
194
|
+
if params.key?('access_token') # has_key
|
195
|
+
if uri_endpoint.include? 'auth'
|
196
|
+
access_token = params['access_token']
|
197
|
+
params.delete('access_token')
|
198
|
+
headers['Authorization'] = 'Bearer ' + access_token
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
if params.key?('apiSecret') # has_key
|
203
|
+
secret_key = params['apiSecret']
|
204
|
+
params.delete('apiSecret')
|
205
|
+
|
206
|
+
if ENV['API_REQUEST_SIGNING'] == 'false' || ENV['API_REQUEST_SIGNING'] == nil
|
207
|
+
headers['X-LoginRadius-ApiSecret'] = secret_key
|
208
|
+
else
|
209
|
+
uri_obj = build_new_uri_obj(uri_endpoint)
|
210
|
+
uri_obj.query = URI.encode_www_form(params)
|
211
|
+
headers = create_hash_secret(uri_obj.request_uri, secret_key, headers, body)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
if params.key?('sott') # has_key
|
215
|
+
headers['X-LoginRadius-Sott'] = params['sott']
|
216
|
+
params.delete('sott')
|
217
|
+
end
|
218
|
+
|
219
|
+
unless ENV['Origin_IP'] == "" || ENV['Origin_IP'] == nil
|
220
|
+
headers['X-Origin-IP'] = ENV['Origin_IP']
|
221
|
+
end
|
222
|
+
|
223
|
+
uri_obj.query = URI.encode_www_form(params)
|
224
|
+
http = Net::HTTP.new(uri_obj.host, uri_obj.port)
|
225
|
+
http.use_ssl = true
|
226
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
227
|
+
req = Net::HTTP::Delete.new(uri_obj.request_uri, headers)
|
228
|
+
req.body = body.to_json
|
229
|
+
response = http.request(req)
|
230
|
+
|
231
|
+
begin
|
232
|
+
return LoginRadius::Response.new(response)
|
233
|
+
rescue JSON::ParserError => e
|
234
|
+
raise LoginRadius::Error.new("JSON parsing error has occurred. More info: #{e.message}")
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
# Builds a URI instance given type and resource
|
239
|
+
#
|
240
|
+
# @param resource [String] Target resource
|
241
|
+
# custom_api_domain is set
|
242
|
+
# @return [URI] uri instance
|
243
|
+
def build_new_uri_obj(resource)
|
244
|
+
if resource == 'ciam/appinfo'
|
245
|
+
return URI.parse(API_V2_BASE_URL_CONFIG + resource)
|
246
|
+
else
|
247
|
+
if ENV['CUSTOM_API_DOMAIN'] == 'false' || ENV['CUSTOM_API_DOMAIN'] == nil
|
248
|
+
return URI.parse(API_V2_BASE_URL + resource)
|
249
|
+
else
|
250
|
+
return URI.parse(ENV['CUSTOM_API_DOMAIN'] + resource)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# Create a has digest in header
|
256
|
+
#
|
257
|
+
# @param endpoint [String] endpoint
|
258
|
+
# @param secret_key [String] secret key
|
259
|
+
# @param headers [String] headers
|
260
|
+
# @param body [String] body
|
261
|
+
# @return [URI] uri instance
|
262
|
+
#
|
263
|
+
# @return [headers] header
|
264
|
+
def create_hash_secret(endpoint, secret_key, headers, body = {})
|
265
|
+
endpoint_uri = 'https://api.loginradius.com' + endpoint
|
266
|
+
expiry_time = (Time.now.getutc() + (1*60*60)).strftime('%Y/%m/%d %H:%M:%S')
|
267
|
+
|
268
|
+
encoded_uri = CGI.escape(CGI.unescape(endpoint_uri))
|
269
|
+
|
270
|
+
if body.blank?
|
271
|
+
string_to_hash = expiry_time + ':' + encoded_uri.downcase
|
272
|
+
else
|
273
|
+
string_to_hash = expiry_time + ':' + encoded_uri.downcase + ':' + body.to_json
|
274
|
+
end
|
275
|
+
|
276
|
+
mac = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), secret_key, string_to_hash)).strip()
|
277
|
+
headers['X-Request-Expires'] = expiry_time
|
278
|
+
headers['digest'] = 'SHA-256='+mac
|
279
|
+
return headers
|
280
|
+
end
|
281
|
+
|
282
|
+
# Local - Generate SOTT:
|
283
|
+
# Generates a Secured One Time Token locally.
|
284
|
+
#
|
285
|
+
# @params validity_length [Integer] Length of time the SOTT is valid for in minutes
|
286
|
+
#
|
287
|
+
# @returns sott [String] LoginRadius Secured One Time Token
|
288
|
+
def local_generate_sott(validity_length = 10)
|
289
|
+
start_time = Time.now.getutc().strftime('%Y/%m/%d %H:%M:%S')
|
290
|
+
end_time = (Time.now.getutc() + (validity_length*60)).strftime('%Y/%m/%d %H:%M:%S')
|
291
|
+
|
292
|
+
plain_text = start_time + '#' + ENV['API_KEY'] + '#' + end_time
|
293
|
+
iter = 10000
|
294
|
+
salt = "\x00\x00\x00\x00\x00\x00\x00\x00"
|
295
|
+
key_len = KEY_SIZE / 8
|
296
|
+
cipher_key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(ENV['API_SECRET'], salt, iter, key_len)
|
297
|
+
|
298
|
+
cipher = OpenSSL::Cipher.new('aes-' + KEY_SIZE.to_s + '-cbc')
|
299
|
+
cipher.encrypt
|
300
|
+
cipher.key = cipher_key
|
301
|
+
cipher.iv = INIT_VECTOR
|
302
|
+
|
303
|
+
encrypted = cipher.update(plain_text) + cipher.final
|
304
|
+
encrypted_b64 = Base64.strict_encode64(encrypted)
|
305
|
+
|
306
|
+
hash = Digest::MD5.hexdigest(encrypted_b64)
|
307
|
+
sott = encrypted_b64 + '*' + hash
|
308
|
+
return sott
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|