From 3196e06bcc4da5f289eb3adf575a00ef343629d5 Mon Sep 17 00:00:00 2001 From: Aaron Cowdin Date: Wed, 5 Jun 2024 07:28:07 -0700 Subject: [PATCH] Update the googleapps IDP provider to work with changes to Google login page while maintaining gaialogin compatibility --- pkg/provider/googleapps/googleapps.go | 58 +++++++++++++++++++++------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/pkg/provider/googleapps/googleapps.go b/pkg/provider/googleapps/googleapps.go index 8409465c0..464fbf127 100644 --- a/pkg/provider/googleapps/googleapps.go +++ b/pkg/provider/googleapps/googleapps.go @@ -63,7 +63,14 @@ func (kc *Client) Authenticate(loginDetails *creds.LoginDetails) (string, error) // Post email address w/o password, then Get the password-input page passwordURL, passwordForm, err := kc.loadLoginPage(authURL+"?hl=en&loc=US", loginDetails.URL+"&hl=en&loc=US", authForm) if err != nil { - return "", errors.Wrap(err, "error loading login page") + //if failed, try with "identifier" + authForm.Set("Email", "") // Clear previous key + authForm.Set("identifier", loginDetails.Username) + passwordURL, passwordForm, err = kc.loadLoginPage(authURL+"?hl=en&loc=US", loginDetails.URL+"&hl=en&loc=US", authForm) + + if err != nil { + return "", errors.Wrap(err, "error loading login page") + } } logger.Debugf("loginURL: %s", passwordURL) @@ -269,7 +276,7 @@ func (kc *Client) loadLoginPage(submitURL string, referer string, authForm url.V loginForm, loginURL, err := extractInputsByFormID(doc, "gaia_loginform", "challenge") if err != nil { return "", nil, errors.Wrap(err, "failed to build login form data") - } + } return loginURL, loginForm, err } @@ -290,6 +297,7 @@ func (kc *Client) loadChallengePage(submitURL string, referer string, authForm u res, err := kc.client.Do(req) if err != nil { + return nil, errors.Wrap(err, "failed to make request to login form") } @@ -311,11 +319,13 @@ func (kc *Client) loadChallengePage(submitURL string, referer string, authForm u secondFactorHeader := "This extra step shows it’s really you trying to sign in" secondFactorHeader2 := "This extra step shows that it’s really you trying to sign in" + secondFactorHeader3 := "2-Step Verification" secondFactorHeaderJp := "2 段階認証プロセス" // have we been asked for 2-Step Verification if extractNodeText(doc, "h2", secondFactorHeader) != "" || extractNodeText(doc, "h2", secondFactorHeader2) != "" || + extractNodeText(doc, "h1", secondFactorHeader3) != "" || extractNodeText(doc, "h1", secondFactorHeaderJp) != "" { responseForm, secondActionURL, err := extractInputsByFormID(doc, "challenge") @@ -326,7 +336,7 @@ func (kc *Client) loadChallengePage(submitURL string, referer string, authForm u logger.Debugf("secondActionURL: %s", secondActionURL) switch { - case strings.Contains(secondActionURL, "challenge/totp/"): // handle TOTP challenge + case strings.Contains(secondActionURL, "challenge/totp"): // handle TOTP challenge var token = loginDetails.MFAToken if token == "" { @@ -337,7 +347,7 @@ func (kc *Client) loadChallengePage(submitURL string, referer string, authForm u responseForm.Set("TrustDevice", "on") // Don't ask again on this computer return kc.loadResponsePage(secondActionURL, submitURL, responseForm) - case strings.Contains(secondActionURL, "challenge/ipp/"): // handle SMS challenge + case strings.Contains(secondActionURL, "challenge/ipp"): // handle SMS challenge if extractNodeText(doc, "button", "Send text message") != "" { responseForm.Set("SendMethod", "SMS") // extractInputsByFormID does not extract the name and value from