You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform配置AWS Cognito的GitHub身份提供商时OIDC错误求助

问题排查与解决方案

核心错误原因

你误用了GitHub Actions专用的OIDC端点https://token.actions.githubusercontent.com,这个地址仅用于CI/CD工作流获取AWS临时凭证,不支持用户身份认证场景,这是触发Cognito报错的直接原因。

修正步骤与代码调整

  1. 替换正确的OIDC Issuer
    GitHub用户认证的合法OIDC Issuer为https://github.com

  2. 调整授权范围
    至少保留openid,建议添加user:email以获取用户邮箱,方便后续用户管理

  3. 补充OIDC端点参数
    手动指定GitHub的OAuth2端点,避免自动发现机制可能出现的异常

  4. 优化属性映射
    将username映射为GitHub的login字段(用户昵称),比原始的sub(用户ID)更贴合业务需求

修正后的Terraform代码:

resource "aws_cognito_identity_provider" "github_provider" {
  user_pool_id     = aws_cognito_user_pool.user_pool.id
  provider_name    = "GitHub"
  provider_type    = "OIDC"

  provider_details = {
    authorize_scopes          = "openid user:email"
    client_id                 = "XXXXXXXXXXXXXXXXX"
    client_secret             = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    oidc_issuer               = "https://github.com"
    attributes_request_method = "GET"
    # 手动指定GitHub OIDC核心端点
    authorize_url             = "https://github.com/login/oauth/authorize"
    token_url                 = "https://github.com/login/oauth/access_token"
    jwks_uri                  = "https://github.com/.well-known/jwks.json"
  }

  attribute_mapping = {
    username = "login"
    email    = "email"
  }
}

额外检查项

  • 确认GitHub OAuth应用的回调地址已设置为Cognito托管UI的回调URL:https://<你的用户池域名>/oauth2/idpresponse
  • 检查Cognito用户池客户端是否已启用GitHub作为身份提供商
  • 验证GitHub OAuth应用的权限配置,确保已开启用户信息访问权限

内容的提问来源于stack exchange,提问作者Tom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 11:02:45