FIX: Downcase email coming back from auth-provider

FIX: Downcase email coming back from auth-provider

diff --git a/lib/auth/result.rb b/lib/auth/result.rb
index 8ad478c..d825758 100644
--- a/lib/auth/result.rb
+++ b/lib/auth/result.rb
@@ -18,6 +18,10 @@ class Auth::Result
     @failed = false
   end
 
+  def email
+    @email.downcase
+  end
+
   def failed?
     !!@failed
   end
diff --git a/spec/components/auth/managed_authenticator_spec.rb b/spec/components/auth/managed_authenticator_spec.rb
index ba463ed..84889de 100644
--- a/spec/components/auth/managed_authenticator_spec.rb
+++ b/spec/components/auth/managed_authenticator_spec.rb
@@ -90,6 +90,11 @@ describe Auth::ManagedAuthenticator do
     end
 
     describe 'match by email' do
+      it 'downcases the email address from the authprovider' do
+        result = authenticator.after_authenticate(hash.deep_merge(info: { email: "HELLO@example.com" }))
+        expect(result.email).to eq('hello@example.com')
+      end
+
       it 'works normally' do
         user = Fabricate(:user)
         result = authenticator.after_authenticate(hash.deep_merge(info: { email: user.email }))

GitHub sha: 296cdc53

@email could be nil, so we need @email&.downcase here

1 Like

FIX: Do not raise exception if the authenticator email is missing