0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

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

Datei anzeigen

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

Datei anzeigen

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