且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自动 gmail 登录 [在 oAuth 期间] 被用户验证阻止

更新时间:2023-11-04 19:47:58

使用 cookie 解决了我的问题

Using cookies solved my issue

public HomePage googleAutoLogin(String cookieKey, String cookieValue) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, 1);
    Date afterOneHour = cal.getTime();

    driver.manage().deleteAllCookies();

    Cookie cookie = new Cookie.Builder(cookieKey, cookieValue)
            .domain("qreflect.com")
            .path("/")
            .expiresOn(afterOneHour)
            .isHttpOnly(true)
            .build();

    driver.manage().addCookie(cookie);
    driver.navigate().refresh();
    logger.log(Level.INFO, "Finished adding cookie");

    return this;
}

您必须手动登录一次,然后检查以获取与您的应用会话相关的 cookie,将它们存储在某处并将键/值对传递给此方法以登录.

you have to login manually once then inspect to get cookies related to your app session, store them somewhere and pass the key/value pair to this method to get logged in.