1
0
Fork 0

a slew of bug fixes to ensure a fault free OAuth 2 authorisation

Dieser Commit ist enthalten in:
Robert Barrow 2019-06-16 16:40:47 +01:00
Ursprung 15e52a5e42
Commit 8db52e0656
3 geänderte Dateien mit 18 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -29,6 +29,7 @@ class CustomWizard::ApiController < ::ApplicationController
CustomWizard::Api.set(api_params[:name], title: api_params[:title])
if auth_data.present?
auth_data['auth_params'] = auth_data['auth_params'] || []
CustomWizard::Api::Authorization.set(api_params[:name], auth_data)
end
@ -66,7 +67,7 @@ class CustomWizard::ApiController < ::ApplicationController
def authorize
result = CustomWizard::Api::Authorization.get_token(api_params[:name])
if result['error']
if result.instance_variable_defined?(:@error)
render json: failed_json.merge(message: result['error_description'] || result['error'])
else
render json: success_json.merge(

Datei anzeigen

@ -41,12 +41,6 @@ class CustomWizard::Api::Authorization
data[k.to_sym] = v
end
data.each do |k, v|
unless new_data.key?(k.to_s)
data.delete(k)
end
end
PluginStore.set("custom_wizard_api_#{api_name}", 'authorization', data)
self.get(api_name)
@ -118,10 +112,10 @@ class CustomWizard::Api::Authorization
)
begin
result = connection.request()
log_params = {time: Time.now, user_id: 0, status: 'SUCCESS', url: token_url, error: ""}
log_params = {time: Time.now, user_id: 0, status: 'SUCCESS', url: authorization.token_url, error: ""}
CustomWizard::Api::LogEntry.set(name, log_params)
rescue
log_params = {time: Time.now, user_id: 0, status: 'FAILURE', url: token_url, error: "Token refresh request failed"}
rescue SystemCallError => e
log_params = {time: Time.now, user_id: 0, status: 'FAILURE', url: authorization.token_url, error: "Token refresh request failed: #{e.inspect}"}
CustomWizard::Api::LogEntry.set(name, log_params)
end

Datei anzeigen

@ -64,11 +64,19 @@ class CustomWizard::Api::LogEntry
data = ::JSON.parse(record['value'])
data[:log_id] = record['key'].split('_').last
this_user = User.find_by(id: data['user_id'])
data[:user_id] = this_user.id || nil
data[:username] = this_user.username || ""
data[:userpath] = "/u/#{this_user.username_lower}/activity"
data[:name] = this_user.name || ""
data[:avatar_template] = "/user_avatar/default/#{this_user.username_lower}/97/#{this_user.uploaded_avatar_id}.png"
unless this_user.nil?
data[:user_id] = this_user.id || nil
data[:username] = this_user.username || ""
data[:userpath] = "/u/#{this_user.username_lower}/activity"
data[:name] = this_user.name || ""
data[:avatar_template] = "/user_avatar/default/#{this_user.username_lower}/97/#{this_user.uploaded_avatar_id}.png"
else
data[:user_id] = nil
data[:username] = ""
data[:userpath] = ""
data[:name] = ""
data[:avatar_template] = ""
end
self.new(api_name, data)
end
end