comments cleanup and added better paramater check for oauth2
Dieser Commit ist enthalten in:
Ursprung
08172d7d35
Commit
0ca8758f6c
1 geänderte Dateien mit 4 neuen und 7 gelöschten Zeilen
|
@ -10,7 +10,6 @@ class CustomWizard::Authorization
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.set_authentication_protocol(service, protocol)
|
def self.set_authentication_protocol(service, protocol)
|
||||||
# TODO: make error more informative
|
|
||||||
raise Discourse::InvalidParameters.new(:protocol) unless [BASIC_AUTH, OAUTH2_AUTH].include? protocol
|
raise Discourse::InvalidParameters.new(:protocol) unless [BASIC_AUTH, OAUTH2_AUTH].include? protocol
|
||||||
PluginStore.set(service, 'authentication_protocol', protocol)
|
PluginStore.set(service, 'authentication_protocol', protocol)
|
||||||
end
|
end
|
||||||
|
@ -80,13 +79,11 @@ class CustomWizard::Authorization
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_header_authorization_string(service)
|
def self.get_header_authorization_string(service)
|
||||||
# TODO: make error more informative, raise error if service not defined
|
|
||||||
protocol = authentication_protocol(service)
|
protocol = authentication_protocol(service)
|
||||||
raise Discourse::InvalidParameters.new(:service) unless protocol.present?
|
raise Discourse::InvalidParameters.new(:service) unless protocol.present?
|
||||||
raise Discourse::InvalidParameters.new(:protocol) unless [BASIC_AUTH, OAUTH2_AUTH].include? protocol
|
raise Discourse::InvalidParameters.new(:protocol) unless [BASIC_AUTH, OAUTH2_AUTH].include? protocol
|
||||||
|
|
||||||
if protocol = BASIC_AUTH
|
if protocol = BASIC_AUTH
|
||||||
# TODO: improve error reporting
|
|
||||||
username = username(service)
|
username = username(service)
|
||||||
raise Discourse::InvalidParameters.new(:username) unless username.present?
|
raise Discourse::InvalidParameters.new(:username) unless username.present?
|
||||||
password = password(service)
|
password = password(service)
|
||||||
|
@ -94,10 +91,10 @@ class CustomWizard::Authorization
|
||||||
authorization_string = (username + ":" + password).chomp
|
authorization_string = (username + ":" + password).chomp
|
||||||
"Basic #{Base64.strict_encode64(authorization_string)}"
|
"Basic #{Base64.strict_encode64(authorization_string)}"
|
||||||
else
|
else
|
||||||
# must be OAUTH2
|
# must be OAUTH2
|
||||||
# TODO: make error more informative, raise error if there is no recorded access token
|
access_token = access_token(service)
|
||||||
raise Discourse::InvalidParameters unless access_token[:token].present?
|
raise Discourse::InvalidParameters.new(access_token) unless access_token.present?
|
||||||
"Bearer #{access_token[:token]}"
|
"Bearer #{access_token}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren