Class: ForestLiana::OidcDynamicClientRegistrator
- Inherits:
-
Object
- Object
- ForestLiana::OidcDynamicClientRegistrator
- Defined in:
- app/services/forest_liana/oidc_dynamic_client_registrator.rb
Class Method Summary collapse
- .authorization_header_value(token, tokenType = 'Bearer') ⇒ Object
- .is_standard_body_error(response) ⇒ Object
- .process_response(response, expected = {}) ⇒ Object
- .register(metadata) ⇒ Object
Class Method Details
.authorization_header_value(token, tokenType = 'Bearer') ⇒ Object
48 49 50 |
# File 'app/services/forest_liana/oidc_dynamic_client_registrator.rb', line 48 def self.(token, tokenType = 'Bearer') return "#{tokenType} #{token}" end |
.is_standard_body_error(response) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/services/forest_liana/oidc_dynamic_client_registrator.rb', line 6 def self.is_standard_body_error(response) result = false begin jsonbody if (!response['body'].is_a?(Object) || response['body'].is_a?(StringIO)) jsonbody = JSON.parse(response['body']) else jsonbody = response['body'] end result = jsonbody['error'].is_a?(String) && jsonbody['error'].length > 0 if (result) response['body'] = jsonbody end rescue {} end return result end |
.process_response(response, expected = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/services/forest_liana/oidc_dynamic_client_registrator.rb', line 29 def self.process_response(response, expected = {}) statusCode = expected[:statusCode] || 200 body = expected[:body] || true if (response.code.to_i != statusCode.to_i) if (is_standard_body_error(response)) raise response['body'] end raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:REGISTRATION_FAILED] + response.body end if (body && !response.body) raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:REGISTRATION_FAILED] + response.body end return response.body end |
.register(metadata) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/services/forest_liana/oidc_dynamic_client_registrator.rb', line 52 def self.register() initial_access_token = ForestLiana.env_secret response = ForestLiana::ForestApiRequester.post( [:registration_endpoint], body: , headers: initial_access_token ? { Authorization: (initial_access_token), } : {}, ) responseBody = process_response(response, { :statusCode => 201, :bearer => true }) return JSON.parse(responseBody) end |