reso_api 1.8.10 → 1.8.11
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 +4 -4
- data/lib/reso_api/app/models/reso/api/client.rb +40 -4
- data/lib/reso_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e81ebb68ef64ed1eb595cf0a92fd03044c03b28e84d40a31fa49e7660ab65a08
|
|
4
|
+
data.tar.gz: 508a035516cbbf60b0d7d606a6277edcf0e72cfb063cf5f2497761f9e1b71d7f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 426229c6c88d7cf4e91f6237989a94b91086af2ef9ad04063638c5ac230851fdccd7a9520d6c30c587cb43009eb93505b93136bb40d2d5894d443fadce286a97
|
|
7
|
+
data.tar.gz: 56f7d6afc8f864cec994b91a1ca8906ef7b48e9209d51fa7e4a8974e03210e254d77f40ccd8e4a238653fbbc47497d6139f3d80d11f161033ac1bb9a5187babc
|
|
@@ -165,6 +165,12 @@ module RESO
|
|
|
165
165
|
@oauth2_payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret, 'scope' => scope.presence)
|
|
166
166
|
File.write(oauth2_token_path, @oauth2_payload.to_hash.to_json)
|
|
167
167
|
return @oauth2_payload
|
|
168
|
+
rescue OAuth2::Error => e
|
|
169
|
+
# Provide detailed error message for OAuth failures
|
|
170
|
+
error_details = "OAuth token refresh failed for #{base_url}"
|
|
171
|
+
error_details += "\n Scope attempted: #{scope.inspect}"
|
|
172
|
+
error_details += "\n OAuth error: #{e.message}"
|
|
173
|
+
raise StandardError, error_details
|
|
168
174
|
rescue => e
|
|
169
175
|
raise StandardError, "Failed to refresh OAuth token: #{e.message}"
|
|
170
176
|
end
|
|
@@ -180,13 +186,43 @@ module RESO
|
|
|
180
186
|
|
|
181
187
|
def get_oauth2_payload
|
|
182
188
|
if File.exist?(oauth2_token_path)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
begin
|
|
190
|
+
persisted = File.read(oauth2_token_path)
|
|
191
|
+
parsed = JSON.parse(persisted)
|
|
192
|
+
|
|
193
|
+
# Check if the persisted data is a valid token (has access_token or token field)
|
|
194
|
+
if parsed['access_token'].present? || parsed['token'].present?
|
|
195
|
+
payload = OAuth2::AccessToken.from_hash(oauth2_client, parsed)
|
|
196
|
+
|
|
197
|
+
# Verify the payload actually has a token
|
|
198
|
+
if payload.token.present?
|
|
199
|
+
return payload
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# If we get here, the cached token is invalid - delete it and get fresh
|
|
204
|
+
File.delete(oauth2_token_path)
|
|
205
|
+
rescue JSON::ParserError, StandardError => e
|
|
206
|
+
# If there's any error reading/parsing the cached token, delete it
|
|
207
|
+
File.delete(oauth2_token_path) if File.exist?(oauth2_token_path)
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# Get fresh token
|
|
212
|
+
begin
|
|
186
213
|
payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret, 'scope' => scope.presence)
|
|
187
214
|
File.write(oauth2_token_path, payload.to_hash.to_json)
|
|
215
|
+
return payload
|
|
216
|
+
rescue OAuth2::Error => e
|
|
217
|
+
# Clean up any bad cached token
|
|
218
|
+
File.delete(oauth2_token_path) if File.exist?(oauth2_token_path)
|
|
219
|
+
|
|
220
|
+
# Provide detailed error message
|
|
221
|
+
error_details = "OAuth token request failed for #{base_url}"
|
|
222
|
+
error_details += "\n Scope attempted: #{scope.inspect}"
|
|
223
|
+
error_details += "\n OAuth error: #{e.message}"
|
|
224
|
+
raise StandardError, error_details
|
|
188
225
|
end
|
|
189
|
-
return payload
|
|
190
226
|
end
|
|
191
227
|
|
|
192
228
|
def uri_for_endpoint endpoint
|
data/lib/reso_api/version.rb
CHANGED