Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

fix: google auth returns given_name/family_name (#66151)

Edward Paget3b837a15a0a2
diff --git a/src/metabase/sso/providers/google.clj b/src/metabase/sso/providers/google.clj
index 86e0d8e8b3c..f50c01175f8 100644
--- a/src/metabase/sso/providers/google.clj
+++ b/src/metabase/sso/providers/google.clj
@@ -27,13 +27,14 @@
:else
(try
(let [token-info-response (http/post (format google-auth-token-info-url token))
- {:keys [first_name last_name email]} (sso.google/google-auth-token-info token-info-response)]
- (log/infof "Successfully authenticated Google Sign-In token for: %s %s" first_name last_name)
+ {first-name :given_name last-name :family_name :keys [email]}
+ (sso.google/google-auth-token-info token-info-response)]
+ (log/infof "Successfully authenticated Google Sign-In token for: %s %s" first-name last-name)
;; Always return user data - let login! handle account creation policy
{:success? true
:user-data {:email email
- :first_name first_name
- :last_name last_name
+ :first_name first-name
+ :last_name last-name
:sso_source :google}
:provider-id email})
(catch clojure.lang.ExceptionInfo e
diff --git a/test/metabase/session/api_test.clj b/test/metabase/session/api_test.clj
index f4047a39eb6..db40180947d 100644
--- a/test/metabase/session/api_test.clj
+++ b/test/metabase/session/api_test.clj
@@ -546,8 +546,8 @@
{:status 200
:body (str "{\"aud\":\"pretend-client-id.apps.googleusercontent.com\","
"\"email_verified\":\"true\","
- "\"first_name\":\"test\","
- "\"last_name\":\"user\","
+ "\"given_name\":\"test\","
+ "\"family_name\":\"user\","
"\"email\":\"[email protected]\"}")})]
(testing "Test that 'remember me' checkbox sets expiration on session"
(let [response (mt/client-real-response :post 200 "session/google_auth" {:token "foo" :remember true})]
@@ -559,17 +559,23 @@
(testing "POST /google_auth"
(mt/with-temporary-setting-values [google-auth-client-id "pretend-client-id.apps.googleusercontent.com"]
(testing "Google auth works with an active account"
- (mt/with-temp [:model/User _ {:email "[email protected]" :is_active true}]
+ (mt/with-temp [:model/User {user-id :id} {:email "[email protected]"
+ :is_active true
+ :first_name "last"
+ :last_name "luser"}]
(with-redefs [http/post (constantly
{:status 200
:body (str "{\"aud\":\"pretend-client-id.apps.googleusercontent.com\","
"\"email_verified\":\"true\","
- "\"first_name\":\"test\","
- "\"last_name\":\"user\","
+ "\"given_name\":\"test\","
+ "\"family_name\":\"user\","
"\"email\":\"[email protected]\"}")})]
(testing "with throttling enabled"
(is (malli= SessionResponse
- (mt/client :post 200 "session/google_auth" {:token "foo"}))))
+ (mt/client :post 200 "session/google_auth" {:token "foo"})))
+ (is (=? {:first_name "test"
+ :last_name "user"}
+ (t2/select-one :model/User user-id))))
(testing "with throttling disabled"
(with-redefs [api.session/throttling-disabled? true]
(is (malli= SessionResponse
@@ -580,8 +586,8 @@
{:status 200
:body (str "{\"aud\":\"pretend-client-id.apps.googleusercontent.com\","
"\"email_verified\":\"true\","
- "\"first_name\":\"test\","
- "\"last_name\":\"user\","
+ "\"given_name\":\"test\","
+ "\"family_name\":\"user\","
"\"email\":\"[email protected]\"}")})]
(is (= {:errors {:_error "Your account is disabled."}}
(mt/client :post 401 "session/google_auth" {:token "foo"})))))))))