1
0
Fork 0

comments cleanup and added better paramater check for oauth2

Dieser Commit ist enthalten in:
Robert Barrow 2019-05-15 08:09:48 +01:00
Ursprung 08172d7d35
Commit 0ca8758f6c

Datei anzeigen

@ -10,7 +10,6 @@ class CustomWizard::Authorization
end
def self.set_authentication_protocol(service, protocol)
# TODO: make error more informative
raise Discourse::InvalidParameters.new(:protocol) unless [BASIC_AUTH, OAUTH2_AUTH].include? protocol
PluginStore.set(service, 'authentication_protocol', protocol)
end
@ -80,13 +79,11 @@ class CustomWizard::Authorization
end
def self.get_header_authorization_string(service)
# TODO: make error more informative, raise error if service not defined
protocol = authentication_protocol(service)
raise Discourse::InvalidParameters.new(:service) unless protocol.present?
raise Discourse::InvalidParameters.new(:protocol) unless [BASIC_AUTH, OAUTH2_AUTH].include? protocol
if protocol = BASIC_AUTH
# TODO: improve error reporting
username = username(service)
raise Discourse::InvalidParameters.new(:username) unless username.present?
password = password(service)
@ -95,9 +92,9 @@ class CustomWizard::Authorization
"Basic #{Base64.strict_encode64(authorization_string)}"
else
# must be OAUTH2
# TODO: make error more informative, raise error if there is no recorded access token
raise Discourse::InvalidParameters unless access_token[:token].present?
"Bearer #{access_token[:token]}"
access_token = access_token(service)
raise Discourse::InvalidParameters.new(access_token) unless access_token.present?
"Bearer #{access_token}"
end
end