适用于AWS驱动的基于浏览器的App的G Suite身份提供程序

hen*_*dry 5 google-api google-login firebase google-oauth

我知道如何通过google-signin-client_id 3089273xx-xxxxxxxxxxxx.apps.googleusercontent.com&创建经过Google身份验证的应用<script src="https://apis.google.com/js/platform.js" async defer></script>,但问题是,我无法将登录限制为仅限我公司的G Suite实例.

我的应用程序是一个托管在S3上的"无服务器"JS包.登录的Google令牌与访问敏感资源的AWS角色相关联.

因此,检查电子邮件googleUser.getBasicProfile()传递hd参数的典型解决方案没有任何安全意义,因为它们可以使用浏览器开发工具IIUC进行操作.

我可以使用其他一些Google API或我可以应用的策略吗?我想这个解决方案将以我公司域名的特殊google-signin-client_id的形式出现,该域名由G Suite托管.这就是它与AWS角色的关系:

AWS IAM Google身份验证

我知道我可以在AWS"用户池"中设置重复的用户并使用Cognito,但我正在尝试为公司员工提供"单一事实来源"并减轻管理负担.

hen*_*dry 3

更新:这个答案是不安全的,就像你简单地删除Hosted_domain一样,你可以使用任何Google登录进行身份验证。

在误入https://developers.google.com/identity/work/it-apps并直接使用 GAPI 之后,我发现我可以做一个

    GAPI.auth2.init({
        client_id: CLIENT_ID,
        hosted_domain: 'example.com'
    })
Run Code Online (Sandbox Code Playgroud)

然后按照文档的建议,您设置管理 API 客户端访问

授权API客户端

所以现在只有Gsuite 上的 @example.com 用户可以访问这个 JS 应用程序!这花了几周时间才弄清楚。总结一下,如何在 AWS 支持的无服务器应用程序上使用 Google 进行身份验证:

  1. 通过OAuth 客户端 ID使用https://console.developers.google.com/apis/credentials中列入白名单的原始 URL设置客户端 ID
  2. AWS IAM中设置一个角色,其中 Google 作为具有客户端 ID 的(网络)身份提供商
  3. 添加您的客户端 ID https://admin.google.com/AdminHome?chromeless=1#OGX:ManageOauthClients,如此处所述https://developers.google.com/identity/work/it-apps,以严格限制您的应用程序公司的域名。

因此,现在我们有一个静态托管的应用程序,仅限公司员工访问敏感的付费 AWS API。