mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 12:36:01 +08:00
FEATURE: raise an exception when the email is missing in the OpenId callback
This commit is contained in:
@ -9,13 +9,14 @@ class Auth::OpenIdAuthenticator < Auth::Authenticator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def after_authenticate(auth_token)
|
def after_authenticate(auth_token)
|
||||||
|
|
||||||
result = Auth::Result.new
|
result = Auth::Result.new
|
||||||
|
|
||||||
data = auth_token[:info]
|
data = auth_token[:info]
|
||||||
identity_url = auth_token[:extra][:response].identity_url
|
identity_url = auth_token[:extra][:response].identity_url
|
||||||
result.email = email = data[:email]
|
result.email = email = data[:email]
|
||||||
|
|
||||||
|
raise Discourse::InvalidParameters.new(:email) if email.blank?
|
||||||
|
|
||||||
# If the auth supplies a name / username, use those. Otherwise start with email.
|
# If the auth supplies a name / username, use those. Otherwise start with email.
|
||||||
result.name = data[:name] || data[:email]
|
result.name = data[:name] || data[:email]
|
||||||
result.username = data[:nickname] || data[:email]
|
result.username = data[:nickname] || data[:email]
|
||||||
|
@ -16,4 +16,10 @@ describe Auth::OpenIdAuthenticator do
|
|||||||
result = auth.after_authenticate(info: {email: user.email}, extra: {response: response})
|
result = auth.after_authenticate(info: {email: user.email}, extra: {response: response})
|
||||||
result.user.should == user
|
result.user.should == user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "raises an exception when email is missing" do
|
||||||
|
auth = Auth::OpenIdAuthenticator.new("test", "id", trusted: true)
|
||||||
|
response = OpenStruct.new(identity_url: 'abc')
|
||||||
|
-> { auth.after_authenticate(info: {}, extra: { response: response }) }.should raise_error(Discourse::InvalidParameters)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user