in pkg/provider/googleapps/googleapps.go [200:284]
func (kc *Client) loadFirstPage(loginDetails *creds.LoginDetails) (string, url.Values, error) {
firstPageURL := loginDetails.URL + "&hl=en&loc=US"
req, err := http.NewRequest("GET", firstPageURL, nil)
if err != nil {
return "", nil, errors.Wrap(err, "error retrieving login form from idp")
}
res, err := kc.client.Do(req)
if err != nil {
return "", nil, errors.Wrap(err, "failed to make request to login form")
}
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
return "", nil, errors.Wrap(err, "error parsing first page html document")
}
doc.Url, err = url.Parse(firstPageURL)
if err != nil {
return "", url.Values{}, errors.Wrap(err, "failed to define URL for html doc")
}
authForm, submitURL, err := extractInputsByFormID(doc, "gaia_loginform", "challenge")
if err != nil {
return "", nil, errors.Wrap(err, "failed to build login form data")
}
_, loginPageV1 := authForm["GALX"]
var postForm url.Values
// using a field which is known to be in the original login page
if loginPageV1 {
// Login page v1
postForm = url.Values{
"bgresponse": []string{"js_disabled"},
"checkConnection": []string{""},
"checkedDomains": []string{"youtube"},
"continue": []string{authForm.Get("continue")},
"gxf": []string{authForm.Get("gxf")},
"identifier-captcha-input": []string{""},
"identifiertoken": []string{""},
"identifiertoken_audio": []string{""},
"ltmpl": []string{"popup"},
"oauth": []string{"1"},
"Page": []string{authForm.Get("Page")},
"Passwd": []string{""},
"PersistentCookie": []string{"yes"},
"ProfileInformation": []string{""},
"pstMsg": []string{"0"},
"sarp": []string{"1"},
"scc": []string{"1"},
"SessionState": []string{authForm.Get("SessionState")},
"signIn": []string{authForm.Get("signIn")},
"_utf8": []string{authForm.Get("_utf8")},
"GALX": []string{authForm.Get("GALX")},
}
} else {
// Login page v2
postForm = url.Values{
"challengeId": []string{"1"},
"challengeType": []string{"1"},
"continue": []string{authForm.Get("continue")},
"scc": []string{"1"},
"sarp": []string{"1"},
"checkeddomains": []string{"youtube"},
"checkConnection": []string{"youtube:930:1"},
"pstMessage": []string{"1"},
"oauth": []string{authForm.Get("oauth")},
"flowName": []string{authForm.Get("flowName")},
"faa": []string{"1"},
"Email": []string{""},
"Passwd": []string{""},
"TrustDevice": []string{"on"},
"bgresponse": []string{"js_disabled"},
}
for _, k := range []string{"TL", "gxf"} {
if v, ok := authForm[k]; ok {
postForm.Set(k, v[0])
}
}
}
return submitURL, postForm, err
}