Cloudformation Cognito - 如何通过SAM模板设置App Client设置,域和联合身份

Jef*_*eff 23 yaml sam amazon-web-services aws-cloudformation cognito

我已经将我的cognito用户池cloudformation模板工作,并将其集成到我的api网关.但不知何故,我仍然需要手动配置应用客户端设置,域和联合身份,以便为用户提供有效的登录门户.我一直在寻找自动化这些的可能解决方案,但我似乎无法找到任何接近它的东西.

我想通过cloudformation sam模板自动配置应用客户端设置,域和联合身份,因此我不必手动执行这些操作.

任何建议都非常感谢.谢谢.

(附件已发布以获取更多信息)

Ros*_*res 36

我创建了两个CloudFormation自定义资源来应用Cognito应用客户端设置和域名.使用这些资源,您可以拥有如下脚本:

UserPoolTestClient:
  Type: 'AWS::Cognito::UserPoolClient'
  Properties:
    ClientName: UserPoolTestClient
    GenerateSecret: true
    UserPoolId: !Ref UserPoolTest
UserPoolTestClientSettings:
  Type: 'Custom::CognitoUserPoolClientSettings'
  Properties:
    ServiceToken: !GetAtt CloudFormationCognitoUserPoolClientSettings.Arn
    UserPoolId: !Ref UserPoolTest
    UserPoolClientId: !Ref UserPoolTestClient
    SupportedIdentityProviders:
      - COGNITO
    CallbackURL: 'https://www.amazon.com'
    LogoutURL: 'https://www.google.com'
    AllowedOAuthFlowsUserPoolClient: true
    AllowedOAuthFlows:
      - code
    AllowedOAuthScopes:
      - openid
UserPoolTestDomain:
  Type: 'Custom::CognitoUserPoolDomain'
  Properties:
    ServiceToken: !GetAtt CloudFormationCognitoUserPoolDomain.Arn
    UserPoolId: !Ref UserPoolTest
    Domain: 'userpool-test-01'
Run Code Online (Sandbox Code Playgroud)

完整的代码在这里.


Mic*_* Z. 27

看起来没有办法通过CloudFormation 提供App集成 - >域名联盟 - >身份提供商.

我发现只有用户池客户端(常规设置 - >应用程序客户端)的参考,但它不会配置应用程序集成 - >应用程序客户端设置.

如果您需要自动化为用户池提供域名,身份提供程序应用程序客户端设置的过程,您可以通过创建应在堆栈部署后执行的自定义脚本(AWS CLI)或Lambda(AWS SDK)来实现.


UPDATE

查看显示使用Lambda 的CloudFormation自定义资源的优秀示例(下面的答案) .

  • 截至 2019 年 10 月 3 日,用户池域可通过 cloudformation 本地实现。请参阅下面 @matsev 的答案或此发布页面 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/ReleaseHistory.html (2认同)

mat*_*sev 9

CloudFormation 添加了资源AWS::Cognito::UserPoolDomain来管理用户池域:

Type: AWS::Cognito::UserPoolDomain
Properties: 
  CustomDomainConfig: 
     CertificateArn: !Ref CertificateArn
  Domain: "your.custom.domain.com"
  UserPoolId: !Ref UserPool
Run Code Online (Sandbox Code Playgroud)

此外,还向AWS::Cognito::UserPoolClient添加了配置:

Type: AWS::Cognito::UserPoolClient
Properties: 
  AllowedOAuthFlows: 
    - String
  AllowedOAuthFlowsUserPoolClient: Boolean
  AllowedOAuthScopes: 
    - String
  AnalyticsConfiguration: 
    AnalyticsConfiguration
  CallbackURLs: 
    - String
  ClientName: String
  DefaultRedirectURI: String
  ExplicitAuthFlows: 
    - String
  GenerateSecret: Boolean
  LogoutURLs: 
    - String
  ReadAttributes: 
    - String
  RefreshTokenValidity: Integer
  SupportedIdentityProviders: 
    - String
  UserPoolId: String
  WriteAttributes: 
    - String
Run Code Online (Sandbox Code Playgroud)


Gre*_*gor 5

从昨天开始,AWS CloudFormation 增加了对直接配置域名、身份和其他设置的原生支持:https : //aws.amazon.com/about-aws/whats-new/2019/10/amazon-cognito-increases-cloudformation-support /

这种新支持包括安全和自动配置托管 UI 域、为托管 UI 配置自定义、配置 IdentityProvider、配置高级安全功能的行为和配置资源服务器的能力,所有这些都直接在 CloudFormation 中完成。

(感谢我的同事 Bernhard 的这次更新)