首页 > 解决方案 > 如何在谷歌oauth登录表单中显示预填的电子邮件

问题描述

我使用 WSO2 作为身份服务器,使用谷歌身份验证器作为身份提供者。登录工作正常。在我的网络应用程序中,我要求用户输入他的电子邮件,然后显示谷歌登录表单。我想显示这封电子邮件以预先填写此表格。谢谢。

在此处输入图像描述

标签: wso2google-oauthwso2is

解决方案


你能行的。为此,您需要自定义 OpenIDConnectAuthenticator.java 以将 login_hint 传递给 google。

建议检查到你服务器中的 org.wso2.carbon.identity.application.authenticator.oidc 版本(你可以在 IS_HOME/repository/components/dropins/ 中找到它)

  • response.sendRedirect(loginPage);在 OpenIDConnectAuthenticator.java之前添加这些行

            String[] usernames = context.getAuthenticationRequest().getRequestQueryParam("username");
            if (usernames != null && usernames.length > 0) {
                loginPage = loginPage + "&login_hint=" + usernames[0];
            }
    

这些行将从身份验证启动请求中获取用户名,并将其作为 login_hint 发送给 google。

  • 使用以下命令构建组件。

mvn clean install

这将在目标文件夹中创建 org.wso2.carbon.identity.application.authenticator.oidc-5.1.17.jar。

  • 替换 IS_HOME/repository/components/dropins 文件夹中现有的 org.wso2.carbon.identity.application.authenticator.oidc-.jar。
  • 重启 IS 服务器
  • 向 IS 发送身份验证请求时附加username=senthalank@gmail.com为 url 参数

例如, https://localhost:9443/oauth2/authorize?response_type=code&client_id=<cliend_id>&redirect_uri=http://localhost:8080/playground2/oauth2client&scope=openid&username=senthalank@gmail.com


推荐阅读