ZOHOCRMSDK2_0 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/ZOHOCRMSDK2_0.rb +6 -0
- data/src/com/zoho/api/authenticator/oauth_token.rb +86 -32
- data/src/com/zoho/api/authenticator/store/db_store.rb +71 -29
- data/src/com/zoho/api/authenticator/store/file_store.rb +95 -24
- data/src/com/zoho/api/authenticator/store/token_store.rb +7 -0
- data/src/com/zoho/api/logger/sdk_logger.rb +19 -9
- data/src/com/zoho/crm/api/contact_roles/api_exception.rb +4 -0
- data/src/com/zoho/crm/api/contact_roles/contact_role_wrapper.rb +61 -0
- data/src/com/zoho/crm/api/contact_roles/contact_roles_operations.rb +118 -0
- data/src/com/zoho/crm/api/contact_roles/record_action_handler.rb +10 -0
- data/src/com/zoho/crm/api/contact_roles/record_action_wrapper.rb +63 -0
- data/src/com/zoho/crm/api/contact_roles/record_body_wrapper.rb +61 -0
- data/src/com/zoho/crm/api/contact_roles/record_response_handler.rb +10 -0
- data/src/com/zoho/crm/api/contact_roles/record_response_wrapper.rb +84 -0
- data/src/com/zoho/crm/api/dc/au_datacenter.rb +3 -3
- data/src/com/zoho/crm/api/dc/cn_datacenter.rb +3 -3
- data/src/com/zoho/crm/api/dc/datacenter.rb +3 -2
- data/src/com/zoho/crm/api/dc/eu_datacenter.rb +3 -3
- data/src/com/zoho/crm/api/dc/in_datacenter.rb +3 -3
- data/src/com/zoho/crm/api/dc/us_datacenter.rb +3 -3
- data/src/com/zoho/crm/api/initializer.rb +44 -16
- data/src/com/zoho/crm/api/record/record_operations.rb +198 -1
- data/src/com/zoho/crm/api/related_records/related_records_operations.rb +299 -40
- data/src/com/zoho/crm/api/request_proxy.rb +3 -4
- data/src/com/zoho/crm/api/sdk_config.rb +2 -68
- data/src/com/zoho/crm/api/util/api_http_connector.rb +6 -6
- data/src/com/zoho/crm/api/util/constants.rb +113 -16
- data/src/com/zoho/crm/api/util/converter.rb +21 -4
- data/src/com/zoho/crm/api/util/data_type_converter.rb +8 -2
- data/src/com/zoho/crm/api/util/form_data_converter.rb +4 -16
- data/src/com/zoho/crm/api/util/json_converter.rb +7 -9
- data/src/com/zoho/crm/api/util/module_fields_handler.rb +1 -1
- data/src/com/zoho/crm/api/util/utility.rb +197 -82
- data/src/resources/JSONDetails.json +1 -1
- data/src/version.rb +2 -2
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95f0344d741c13094abf8b93a67139018a0b83895f612a9be53fb7e32f14217b
|
4
|
+
data.tar.gz: 8fc22f398327570fe85162016f887c280d2485e6ffdc6e82c671963a1bd7976e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a30421d88bd8b9b915998fbfaecf567e7f99a2534f86427e0f8e804a6a55a247f31f36239287e22b7e1112ee7902b768b7f783f80180dfca77e6f951d605bc69
|
7
|
+
data.tar.gz: 7481d802d6be8ca33d3f723b560e312d21f49dfc6afa27e0e2ea03599f2a23458417d9a0a18fbf9ef7ba5e1ade40e0601cc41eb0718fb892ffd5e0569c78a209
|
data/src/ZOHOCRMSDK2_0.rb
CHANGED
@@ -202,11 +202,17 @@ require 'com/zoho/crm/api/contact_roles/contact_role.rb'
|
|
202
202
|
require 'com/zoho/crm/api/contact_roles/body_wrapper.rb'
|
203
203
|
require 'com/zoho/crm/api/contact_roles/action_handler.rb'
|
204
204
|
require 'com/zoho/crm/api/contact_roles/action_wrapper.rb'
|
205
|
+
require 'com/zoho/crm/api/contact_roles/record_action_handler.rb'
|
206
|
+
require 'com/zoho/crm/api/contact_roles/record_response_handler.rb'
|
207
|
+
require 'com/zoho/crm/api/contact_roles/record_action_wrapper.rb'
|
208
|
+
require 'com/zoho/crm/api/contact_roles/record_body_wrapper.rb'
|
209
|
+
require 'com/zoho/crm/api/contact_roles/record_response_wrapper.rb'
|
205
210
|
require 'com/zoho/crm/api/contact_roles/response_wrapper.rb'
|
206
211
|
require 'com/zoho/crm/api/contact_roles/api_exception.rb'
|
207
212
|
require 'com/zoho/crm/api/contact_roles/contact_roles_operations.rb'
|
208
213
|
require 'com/zoho/crm/api/contact_roles/success_response.rb'
|
209
214
|
require 'com/zoho/crm/api/contact_roles/action_response.rb'
|
215
|
+
require 'com/zoho/crm/api/contact_roles/contact_role_wrapper.rb'
|
210
216
|
require 'com/zoho/crm/api/contact_roles/response_handler.rb'
|
211
217
|
require 'com/zoho/crm/api/layouts/layouts_operations.rb'
|
212
218
|
require 'com/zoho/crm/api/layouts/section.rb'
|
@@ -11,19 +11,19 @@ require_relative '../../crm/api/exception/sdk_exception'
|
|
11
11
|
module Authenticator
|
12
12
|
# This class gets and refreshes the tokens based on the expiry time.
|
13
13
|
class OAuthToken < Token
|
14
|
+
attr_accessor :client_id , :client_secret ,:redirect_url ,:grant_token,:refresh_token, :access_token ,:user_mail ,:id ,:expires_in
|
14
15
|
@@sync_lock = Monitor.new
|
15
16
|
|
16
|
-
attr_accessor :client_id, :client_secret, :redirect_url, :grant_token, :refresh_token, :access_token, :expires_in, :user_mail, :id
|
17
|
-
|
18
17
|
# Creates an OAuthToken class instance with the specified parameters.
|
19
18
|
# @param client_id [string] A String containing the OAuth client id.
|
20
19
|
# @param client_secret [string] A String containing the OAuth client secret.
|
20
|
+
# @param grant_token [string] A String containing the grant token.
|
21
|
+
# @param refresh_token [string] A String containing the refresh token.
|
21
22
|
# @param redirect_url [string] A String containing the OAuth redirect URL.
|
22
|
-
# @param
|
23
|
-
|
24
|
-
def initialize(client_id
|
25
|
-
error =
|
26
|
-
|
23
|
+
# @param id [string] A String containing ID
|
24
|
+
|
25
|
+
def initialize(client_id:, client_secret:, grant_token: nil, refresh_token: nil, redirect_url: nil,id: nil)
|
26
|
+
error ={}
|
27
27
|
unless client_id.is_a?(String)
|
28
28
|
error[Constants::ERROR_HASH_FIELD] = Constants::CLIENT_ID
|
29
29
|
|
@@ -35,7 +35,7 @@ module Authenticator
|
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
-
unless client_secret.
|
38
|
+
unless client_secret.is_a?(String)
|
39
39
|
error[Constants::ERROR_HASH_FIELD] = Constants::CLIENT_SECRET
|
40
40
|
|
41
41
|
error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
|
@@ -46,8 +46,41 @@ module Authenticator
|
|
46
46
|
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
error[Constants::ERROR_HASH_FIELD] = Constants::
|
49
|
+
if !grant_token.nil? && !grant_token.is_a?(String)
|
50
|
+
error[Constants::ERROR_HASH_FIELD] = Constants::GRANT_TOKEN
|
51
|
+
|
52
|
+
error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
|
53
|
+
|
54
|
+
error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
|
55
|
+
|
56
|
+
raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
if !refresh_token.nil? && !refresh_token.is_a?(String)
|
61
|
+
error[Constants::ERROR_HASH_FIELD] = Constants::REFRESH_TOKEN
|
62
|
+
|
63
|
+
error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
|
64
|
+
|
65
|
+
error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
|
66
|
+
|
67
|
+
raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
if !redirect_url.nil? && !redirect_url.is_a?(String)
|
72
|
+
error[Constants::ERROR_HASH_FIELD] = Constants::REDIRECT_URL
|
73
|
+
|
74
|
+
error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
|
75
|
+
|
76
|
+
error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
|
77
|
+
|
78
|
+
raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
if !id.nil? && !id.is_a?(String)
|
83
|
+
error[Constants::ERROR_HASH_FIELD] = Constants::ID
|
51
84
|
|
52
85
|
error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
|
53
86
|
|
@@ -57,7 +90,7 @@ module Authenticator
|
|
57
90
|
|
58
91
|
end
|
59
92
|
|
60
|
-
|
93
|
+
if grant_token.nil? && refresh_token.nil?
|
61
94
|
error[Constants::ERROR_HASH_FIELD] = Constants::TYPE
|
62
95
|
|
63
96
|
error[Constants::ERROR_HASH_EXPECTED_TYPE] = Constants::EXPECTED_TOKEN_TYPES
|
@@ -66,28 +99,39 @@ module Authenticator
|
|
66
99
|
|
67
100
|
raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
|
68
101
|
end
|
69
|
-
|
70
102
|
@client_id = client_id
|
71
103
|
|
72
104
|
@client_secret = client_secret
|
73
105
|
|
74
106
|
@redirect_url = redirect_url
|
75
107
|
|
76
|
-
@refresh_token =
|
108
|
+
@refresh_token = refresh_token
|
77
109
|
|
78
|
-
@grant_token =
|
79
|
-
|
110
|
+
@grant_token = grant_token
|
111
|
+
|
112
|
+
@access_token = nil
|
113
|
+
|
114
|
+
@expires_in = nil
|
80
115
|
|
116
|
+
@user_mail = nil
|
117
|
+
|
118
|
+
@id = id
|
119
|
+
end
|
120
|
+
|
81
121
|
def authenticate(url_connection)
|
82
122
|
@@sync_lock.synchronize do
|
83
123
|
initializer = Initializer.get_initializer
|
84
124
|
store = initializer.store
|
85
|
-
|
86
125
|
user = initializer.user
|
87
126
|
|
88
|
-
oauth_token =
|
127
|
+
oauth_token = nil
|
128
|
+
if !@id.nil?
|
129
|
+
oauth_token = initializer.store.get_token_by_id(@id, self)
|
130
|
+
else
|
131
|
+
oauth_token = initializer.store.get_token(user, self)
|
132
|
+
end
|
89
133
|
|
90
|
-
token =
|
134
|
+
token = ""
|
91
135
|
|
92
136
|
if oauth_token.nil?
|
93
137
|
token = @refresh_token.nil? ? generate_access_token(user, store).access_token : refresh_access_token(user, store).access_token
|
@@ -97,7 +141,6 @@ module Authenticator
|
|
97
141
|
else
|
98
142
|
token = oauth_token.access_token
|
99
143
|
end
|
100
|
-
|
101
144
|
url_connection.headers[Constants::AUTHORIZATION] = Constants::OAUTH_HEADER_PREFIX + token
|
102
145
|
end
|
103
146
|
end
|
@@ -115,8 +158,8 @@ module Authenticator
|
|
115
158
|
json_body[Constants::CLIENT_ID] = @client_id
|
116
159
|
|
117
160
|
json_body[Constants::CLIENT_SECRET] = @client_secret
|
118
|
-
|
119
|
-
json_body[Constants::REDIRECT_URI] = @redirect_url
|
161
|
+
|
162
|
+
json_body[Constants::REDIRECT_URI] = @redirect_url if !@redirect_url.nil?
|
120
163
|
|
121
164
|
json_body[Constants::GRANT_TYPE] = Constants::GRANT_TYPE_AUTH_CODE
|
122
165
|
|
@@ -125,7 +168,11 @@ module Authenticator
|
|
125
168
|
response = get_response_from_server(json_body)
|
126
169
|
|
127
170
|
begin
|
128
|
-
|
171
|
+
parse_response(response)
|
172
|
+
|
173
|
+
generate_id()
|
174
|
+
|
175
|
+
store.save_token(user,self)
|
129
176
|
rescue SDKException => e
|
130
177
|
raise e
|
131
178
|
rescue StandardError => e
|
@@ -141,7 +188,7 @@ module Authenticator
|
|
141
188
|
|
142
189
|
json_body[Constants::CLIENT_SECRET] = @client_secret
|
143
190
|
|
144
|
-
json_body[Constants::REDIRECT_URI] = @redirect_url
|
191
|
+
json_body[Constants::REDIRECT_URI] = @redirect_url if !@redirect_url.nil?
|
145
192
|
|
146
193
|
json_body[Constants::GRANT_TYPE] = Constants::REFRESH_TOKEN
|
147
194
|
|
@@ -150,7 +197,11 @@ module Authenticator
|
|
150
197
|
response = get_response_from_server(json_body)
|
151
198
|
|
152
199
|
begin
|
153
|
-
|
200
|
+
parse_response(response)
|
201
|
+
|
202
|
+
generate_id()
|
203
|
+
|
204
|
+
store.save_token(user,self)
|
154
205
|
rescue SDKException => e
|
155
206
|
raise e
|
156
207
|
rescue StandardError => e
|
@@ -184,7 +235,7 @@ module Authenticator
|
|
184
235
|
http.use_ssl = true
|
185
236
|
|
186
237
|
request = Net::HTTP::Post.new(url.request_uri)
|
187
|
-
|
238
|
+
request.add_field(Constants::USER_AGENT_KEY, Constants::USER_AGENT)
|
188
239
|
request.set_form(json_body, Constants::APPLICATION_FORM_URLENCODED)
|
189
240
|
|
190
241
|
response = http.request(request)
|
@@ -207,11 +258,14 @@ module Authenticator
|
|
207
258
|
def get_current_time_in_millis
|
208
259
|
(Time.now.to_f * 1000).to_i
|
209
260
|
end
|
210
|
-
end
|
211
|
-
end
|
212
261
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
262
|
+
def generate_id
|
263
|
+
id = ""
|
264
|
+
email = Initializer.get_initializer.user.email
|
265
|
+
environment = Initializer.get_initializer.environment.name
|
266
|
+
id = id + "ruby_" +email[0..email.index(Constants::AT) - 1] + Constants::UNDERSCORE
|
267
|
+
id = id + environment + Constants::UNDERSCORE + @refresh_token[@refresh_token.length-4..@refresh_token.length-1]
|
268
|
+
@id = id
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
@@ -6,24 +6,22 @@ require_relative '../../../crm/api/util/constants'
|
|
6
6
|
module Store
|
7
7
|
# This class stores the user token details to the MySQL DataBase.
|
8
8
|
class DBStore < TokenStore
|
9
|
-
|
9
|
+
attr_reader :user_name, :password, :port_number, :host, :database_name, :table_name
|
10
10
|
|
11
11
|
# Creates an DBStore class instance with the specified parameters.
|
12
12
|
# @param host [string] A String containing the DataBase host name.
|
13
13
|
# @param database_name A String containing the DataBase name.
|
14
|
+
# @param table_name A String containing the table name.
|
14
15
|
# @param user_name A String containing the DataBase user name.
|
15
16
|
# @param password A String containing the DataBase password.
|
16
17
|
# @param port_number A String containing the DataBase port number.
|
17
|
-
def initialize(host
|
18
|
-
@host = host
|
19
|
-
|
20
|
-
@
|
21
|
-
|
22
|
-
@
|
23
|
-
|
24
|
-
@password = password.nil? ? '' : password
|
25
|
-
|
26
|
-
@port_number = port_number.nil? ? Constants::MYSQL_PORT_NUMBER : port_number
|
18
|
+
def initialize(host: Constants::MYSQL_HOST, database_name: Constants::MYSQL_DATABASE_NAME ,table_name: Constants::MYSQL_TABLE_NAME,user_name: Constants::MYSQL_USER_NAME,password: '',port_number: Constants::MYSQL_PORT_NUMBER )
|
19
|
+
@host = host
|
20
|
+
@database_name = database_name
|
21
|
+
@table_name = table_name
|
22
|
+
@user_name = user_name
|
23
|
+
@password = password
|
24
|
+
@port_number = port_number
|
27
25
|
end
|
28
26
|
|
29
27
|
def get_token(user, token)
|
@@ -38,12 +36,24 @@ module Store
|
|
38
36
|
rs.each do |row|
|
39
37
|
oauthtoken = token
|
40
38
|
|
41
|
-
oauthtoken.
|
39
|
+
oauthtoken.client_id = row[Constants::CLIENT_ID]
|
42
40
|
|
43
|
-
oauthtoken.
|
41
|
+
oauthtoken.client_secret = row[Constants::CLIENT_SECRET]
|
42
|
+
|
43
|
+
oauthtoken.grant_token = row[Constants::GRANT_TOKEN]
|
44
|
+
|
45
|
+
oauthtoken.redirect_url = row[Constants::REDIRECT_URL]
|
44
46
|
|
45
47
|
oauthtoken.refresh_token = row[Constants::REFRESH_TOKEN]
|
46
48
|
|
49
|
+
oauthtoken.id = row[Constants::ID]
|
50
|
+
|
51
|
+
oauthtoken.user_mail = row[Constants::USER_MAIL]
|
52
|
+
|
53
|
+
oauthtoken.access_token = row[Constants::ACCESS_TOKEN]
|
54
|
+
|
55
|
+
oauthtoken.expires_in = row[Constants::EXPIRY_TIME]
|
56
|
+
|
47
57
|
return oauthtoken
|
48
58
|
end
|
49
59
|
nil
|
@@ -54,7 +64,7 @@ module Store
|
|
54
64
|
def save_token(user, token)
|
55
65
|
con = Mysql2::Client.new(host: @host, username: @user_name, password: @password, database: @database_name, port: @port_number)
|
56
66
|
if token.is_a? Authenticator::OAuthToken
|
57
|
-
query = "insert into
|
67
|
+
query = "insert into #{token.table_name}(id,user_mail,client_id,client_secret,refresh_token,access_token,grant_token,expiry_time,redirect_url) values ('#{token.id}','#{user.email}','#{token.client_id}','#{token.client_secret}','#{token.refresh_token}','#{token.access_token}','#{token.grant_token}','#{token.expires_in}','#{token.redirect_url}')"
|
58
68
|
token.user_mail = user.email
|
59
69
|
delete_token(token)
|
60
70
|
con.query(query)
|
@@ -81,7 +91,7 @@ module Store
|
|
81
91
|
def delete_tokens
|
82
92
|
con = Mysql2::Client.new(host: @host, username: @user_name, password: @password, database: @database_name, port: @port_number)
|
83
93
|
|
84
|
-
query =
|
94
|
+
query = "delete * from #{@table_name}"
|
85
95
|
|
86
96
|
con.query(query)
|
87
97
|
|
@@ -94,24 +104,16 @@ module Store
|
|
94
104
|
tokens = []
|
95
105
|
con = Mysql2::Client.new(host: @host, username: @user_name, password: @password, database: @database_name, port: @port_number)
|
96
106
|
|
97
|
-
query =
|
107
|
+
query = "select * from #{@table_name}"
|
98
108
|
|
99
109
|
rs = con.query(query)
|
100
110
|
|
101
111
|
con.close
|
102
112
|
|
103
113
|
rs.each do |row|
|
104
|
-
token_type = nil
|
105
|
-
token_value = nil
|
106
|
-
if !row[Constants::GRANT_TOKEN].nil? && row[Constants::GRANT_TOKEN].length.positive?
|
107
|
-
token_type = TokenType::GRANT
|
108
|
-
token_value = row[Constants::GRANT_TOKEN]
|
109
|
-
else
|
110
|
-
token_type = TokenType::REFRESH
|
111
|
-
token_value = row[Constants::REFRESH_TOKEN]
|
112
|
-
end
|
113
114
|
|
114
|
-
|
115
|
+
|
116
|
+
oauthtoken = Authenticator::OAuthToken.new(client_id: row[Constants::CLIENT_ID],client_secret: row[Constants::CLIENT_SECRET],grant_token: grant_token,refresh_token: row[Constants::REFRESH_TOKEN])
|
115
117
|
|
116
118
|
oauthtoken.id = row[Constants::ID]
|
117
119
|
|
@@ -119,9 +121,9 @@ module Store
|
|
119
121
|
|
120
122
|
oauthtoken.access_token = row[Constants::ACCESS_TOKEN]
|
121
123
|
|
122
|
-
oauthtoken.
|
124
|
+
oauthtoken.redirect_url = row[Constants::REDIRECT_URL]
|
123
125
|
|
124
|
-
oauthtoken.
|
126
|
+
oauthtoken.expires_in = row[Constants::EXPIRY_TIME]
|
125
127
|
|
126
128
|
tokens.push(oauthtoken)
|
127
129
|
end
|
@@ -135,7 +137,7 @@ module Store
|
|
135
137
|
|
136
138
|
query = is_delete ? 'delete from ' : 'select * from '
|
137
139
|
|
138
|
-
query +=
|
140
|
+
query += "#{@table_name} where user_mail='#{email}' and client_id='#{token.client_id}' and "
|
139
141
|
|
140
142
|
query += if token.grant_token.nil?
|
141
143
|
"refresh_token='#{token.refresh_token}'"
|
@@ -145,5 +147,45 @@ module Store
|
|
145
147
|
|
146
148
|
query
|
147
149
|
end
|
150
|
+
def get_token_by_id(id,token)
|
151
|
+
con = Mysql2::Client.new(host: @host, username: @user_name, password: @password, database: @database_name, port: @port_number)
|
152
|
+
|
153
|
+
if token.is_a? Authenticator::OAuthToken
|
154
|
+
query = "select * from #{@table_name} where id='#{id}'"
|
155
|
+
|
156
|
+
rs = con.query(query)
|
157
|
+
|
158
|
+
con.close
|
159
|
+
|
160
|
+
rs.each do |row|
|
161
|
+
if id == row[Constants::ID]
|
162
|
+
oauthtoken = token
|
163
|
+
|
164
|
+
oauthtoken.client_id = row[Constants::CLIENT_ID]
|
165
|
+
|
166
|
+
oauthtoken.client_secret = row[Constants::CLIENT_SECRET]
|
167
|
+
|
168
|
+
oauthtoken.grant_token = row[Constants::GRANT_TOKEN]
|
169
|
+
|
170
|
+
oauthtoken.redirect_url = row[Constants::REDIRECT_URL]
|
171
|
+
|
172
|
+
oauthtoken.refresh_token = row[Constants::REFRESH_TOKEN]
|
173
|
+
|
174
|
+
oauthtoken.id = row[Constants::ID]
|
175
|
+
|
176
|
+
oauthtoken.user_mail = row[Constants::USER_MAIL]
|
177
|
+
|
178
|
+
oauthtoken.access_token = row[Constants::ACCESS_TOKEN]
|
179
|
+
|
180
|
+
oauthtoken.expires_in = row[Constants::EXPIRY_TIME]
|
181
|
+
|
182
|
+
return oauthtoken
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
nil
|
187
|
+
rescue Mysql2::Error => e
|
188
|
+
raise SDKException.new(Constants::TOKEN_STORE, Constants::GET_TOKEN_BY_ID_DB_ERROR, nil, e)
|
189
|
+
end
|
148
190
|
end
|
149
191
|
end
|
@@ -16,7 +16,7 @@ module Store
|
|
16
16
|
|
17
17
|
unless File.exist? @file_path
|
18
18
|
File.new(@file_path, 'w')
|
19
|
-
@csv_file = CSV.open(@file_path, 'a', write_headers: true, headers: [Constants::USER_MAIL, Constants::CLIENT_ID, Constants::REFRESH_TOKEN, Constants::ACCESS_TOKEN, Constants::GRANT_TOKEN, Constants::EXPIRY_TIME])
|
19
|
+
@csv_file = CSV.open(@file_path, 'a', write_headers: true, headers: [Constants::ID,Constants::USER_MAIL, Constants::CLIENT_ID,Constants::CLIENT_SECRET, Constants::REFRESH_TOKEN, Constants::ACCESS_TOKEN, Constants::GRANT_TOKEN, Constants::EXPIRY_TIME,Constants::REDIRECT_URL])
|
20
20
|
end
|
21
21
|
@csv_file = CSV.open(@file_path, 'a')
|
22
22
|
end
|
@@ -38,15 +38,33 @@ module Store
|
|
38
38
|
end
|
39
39
|
|
40
40
|
file_contents.each do |row|
|
41
|
-
token_check = grant_token.nil? ? refresh_token == row[
|
41
|
+
token_check = grant_token.nil? ? refresh_token == row[4] : grant_token == row[6]
|
42
|
+
if (row[1] == user_email) && (row[2] == client_id) && token_check
|
42
43
|
|
43
|
-
|
44
|
-
token.refresh_token = row[2]
|
44
|
+
grant_token = (!row[6].nil? && !row[6].empty?) ? row[6] : nil
|
45
45
|
|
46
|
-
|
46
|
+
redirect_url = (!row[8].nil? && !row[8].empty?) ? row[8] : nil
|
47
|
+
|
48
|
+
oauthtoken = token
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
+
oauthtoken.id = row[0]
|
51
|
+
|
52
|
+
oauthtoken.user_mail = row[1]
|
53
|
+
|
54
|
+
oauthtoken.client_id = row[2]
|
55
|
+
|
56
|
+
oauthtoken.client_secret = row[3]
|
57
|
+
|
58
|
+
oauthtoken.refresh_token = row[4]
|
59
|
+
|
60
|
+
oauthtoken.access_token = row[5]
|
61
|
+
|
62
|
+
oauthtoken.grant_token = grant_token
|
63
|
+
|
64
|
+
oauthtoken.expires_in = row[7]
|
65
|
+
|
66
|
+
oauthtoken.redirect_url = redirect_url
|
67
|
+
return oauthtoken
|
50
68
|
end
|
51
69
|
end
|
52
70
|
end
|
@@ -60,25 +78,21 @@ module Store
|
|
60
78
|
file_contents = CSV.table(@file_path)
|
61
79
|
file_contents.each do |row|
|
62
80
|
unless row == @csv_file.header_row?
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
token_type = TokenType::GRANT
|
67
|
-
token_value = row[4]
|
68
|
-
else
|
69
|
-
token_type = TokenType::REFRESH
|
70
|
-
token_value = row[2]
|
71
|
-
end
|
81
|
+
grant_token = (!row[6].nil? && !row[6].empty?) ? row[6] : nil
|
82
|
+
|
83
|
+
redirect_url = (!row[8].nil? && !row[8].empty?) ? row[8] : nil
|
72
84
|
|
73
|
-
token = Authenticator::OAuthToken.new(row[
|
85
|
+
token = Authenticator::OAuthToken.new(client_id: row[2],client_secret: row[3],grant_token: grant_token,refresh_token: row[4])
|
86
|
+
|
87
|
+
token.id = row[0]
|
74
88
|
|
75
|
-
token.user_mail = row[
|
89
|
+
token.user_mail = row[1]
|
76
90
|
|
77
|
-
token.
|
91
|
+
token.access_token = row[5]
|
78
92
|
|
79
|
-
token.
|
93
|
+
token.expires_in = row[7]
|
80
94
|
|
81
|
-
token.
|
95
|
+
token.redirect_url = redirect_url
|
82
96
|
|
83
97
|
tokens.push(token)
|
84
98
|
end
|
@@ -96,10 +110,14 @@ module Store
|
|
96
110
|
delete_token(token)
|
97
111
|
values_list = []
|
98
112
|
|
113
|
+
values_list.push(token.id)
|
114
|
+
|
99
115
|
values_list.push(user.email)
|
100
116
|
|
101
117
|
values_list.push(token.client_id)
|
102
118
|
|
119
|
+
values_list.push(token.client_secret)
|
120
|
+
|
103
121
|
values_list.push(token.refresh_token)
|
104
122
|
|
105
123
|
values_list.push(token.access_token)
|
@@ -107,6 +125,8 @@ module Store
|
|
107
125
|
values_list.push(token.grant_token)
|
108
126
|
|
109
127
|
values_list.push(token.expires_in)
|
128
|
+
|
129
|
+
values_list.push(token.redirect_url)
|
110
130
|
end
|
111
131
|
@csv_file = CSV.open(@file_path, 'a') if @csv_file.closed?
|
112
132
|
@csv_file << values_list
|
@@ -118,6 +138,7 @@ module Store
|
|
118
138
|
|
119
139
|
def delete_token(token)
|
120
140
|
if token.is_a? Authenticator::OAuthToken
|
141
|
+
|
121
142
|
grant_token = token.grant_token
|
122
143
|
|
123
144
|
refresh_token = token.refresh_token
|
@@ -134,9 +155,10 @@ module Store
|
|
134
155
|
|
135
156
|
table.delete_if do |row|
|
136
157
|
unless row == @csv_file.header_row?
|
137
|
-
|
138
|
-
|
139
|
-
|
158
|
+
|
159
|
+
token_check = grant_token.nil? ? refresh_token == row[4] : grant_token == row[6]
|
160
|
+
|
161
|
+
row[1] == user_email and row[2] == client_id and token_check
|
140
162
|
end
|
141
163
|
end
|
142
164
|
|
@@ -161,5 +183,54 @@ module Store
|
|
161
183
|
rescue StandardError => e
|
162
184
|
raise SDKException.new(Constants::TOKEN_STORE, Constants::DELETE_TOKENS_FILE_ERROR, nil, e)
|
163
185
|
end
|
186
|
+
|
187
|
+
def get_token_by_id(id, token)
|
188
|
+
if token.is_a? Authenticator::OAuthToken
|
189
|
+
|
190
|
+
is_row_present = false
|
191
|
+
|
192
|
+
file_contents = CSV.read(@file_path)
|
193
|
+
|
194
|
+
file_contents.each do |row|
|
195
|
+
|
196
|
+
if row[0] == id
|
197
|
+
|
198
|
+
is_row_present = true
|
199
|
+
|
200
|
+
grant_token = (!row[6].nil? && !row[6].empty?) ? row[6] : nil
|
201
|
+
|
202
|
+
redirect_url = (!row[8].nil? && !row[8].empty?) ? row[8] : nil
|
203
|
+
|
204
|
+
oauthtoken = token
|
205
|
+
|
206
|
+
oauthtoken.id = row[0]
|
207
|
+
|
208
|
+
oauthtoken.user_mail = row[1]
|
209
|
+
|
210
|
+
oauthtoken.client_id = row[2]
|
211
|
+
|
212
|
+
oauthtoken.client_secret = row[3]
|
213
|
+
|
214
|
+
oauthtoken.refresh_token = row[4]
|
215
|
+
|
216
|
+
oauthtoken.access_token = row[5]
|
217
|
+
|
218
|
+
oauthtoken.grant_token = grant_token
|
219
|
+
|
220
|
+
oauthtoken.expires_in = row[7]
|
221
|
+
|
222
|
+
oauthtoken.redirect_url = redirect_url
|
223
|
+
|
224
|
+
return oauthtoken
|
225
|
+
end
|
226
|
+
end
|
227
|
+
if !is_row_present
|
228
|
+
raise SDKException.new(Constants::TOKEN_STORE, Constants::GET_TOKEN_BY_ID_FILE_ERROR, nil, nil)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
nil
|
232
|
+
rescue StandardError => e
|
233
|
+
raise SDKException.new(Constants::TOKEN_STORE, Constants::GET_TOKEN_BY_ID_FILE_ERROR, nil, e)
|
234
|
+
end
|
164
235
|
end
|
165
236
|
end
|