Cognito 用户池作为具有客户端凭据的身份提供者仅在保存到 aws 控制台后才有效
Posted
技术标签:
【中文标题】Cognito 用户池作为具有客户端凭据的身份提供者仅在保存到 aws 控制台后才有效【英文标题】:Cognito Userpool as identy provider with client credentials works only after saving in aws console 【发布时间】:2021-11-22 11:05:27 【问题描述】:我正在使用无服务器框架在 aws 中部署无服务器应用程序。我正在使用 cognito 用户池和客户端凭据身份验证设置 AUTH2。 部署后它不起作用,当我通过邮递员请求新令牌时,我收到错误无效授权。 当我登录到 aws 控制台时,打开 cognito 应用程序客户端页面(刷新页面)并单击“保存”按钮(不更改任何内容),它可以工作。我可以请求作为访问令牌并可以登录到我的应用程序。 它在我的下一次部署之前一直有效,因此无法进行自动部署。可能是什么原因?当我点击保存按钮时会发生什么? 这是我的部署代码
resources:
资源:
UserPoolDomain:
Type: AWS::Cognito::UserPoolDomain
Properties:
UserPoolId:
Ref: CognitoUserPool
Domain: "myapp-user-pool-domain"
CognitoUserPool:
Type: "AWS::Cognito::UserPool"
Properties:
MfaConfiguration: OFF
UserPoolName: myapp-user-pool
AdminCreateUserConfig:
AllowAdminCreateUserOnly: true
UsernameAttributes:
- email
CognitoUserPoolClient:
Type: "AWS::Cognito::UserPoolClient"
Properties:
ClientName: myapp-user-pool-client
GenerateSecret: True
UserPoolId:
Ref: CognitoUserPool
AllowedOAuthFlows: [ "client_credentials"]
ExplicitAuthFlows: ["ALLOW_USER_PASSWORD_AUTH","ALLOW_REFRESH_TOKEN_AUTH" ]
SupportedIdentityProviders: [ "COGNITO" ]
AllowedOAuthScopes: [ "myapp/odata4","myapp/trigger" ]
PreventUserExistenceErrors: ENABLED
ApiGatewayAuthorizer:
DependsOn:
- ApiGatewayRestApi
Type: AWS::ApiGateway::Authorizer
Properties:
Name: cognito-authorizer
IdentitySource: method.request.header.Authorization
RestApiId:
Ref: ApiGatewayRestApi
Type: COGNITO_USER_POOLS
ProviderARNs:
- Fn::GetAtt: [ CognitoUserPool, Arn ]
UserPoolResourceServer:
Type: AWS::Cognito::UserPoolResourceServer
Properties:
UserPoolId:
Ref: CognitoUserPool
Identifier: "myapp"
Name: "myapp"
Scopes:
- ScopeName: "results"
ScopeDescription: "provides myapp results"
- ScopeName: "trigger"
ScopeDescription: "trigger for myapp start"
谁能帮忙? 谢谢
【问题讨论】:
我过去肯定遇到过类似的问题。他们似乎在其 CloudFormation 提供商中存在未解决的验证问题。 【参考方案1】:必须将以下行添加到 CognitoUserPoolClient:AllowedOAuthFlowsUserPoolClient: True
。然后就可以了。
【讨论】:
以上是关于Cognito 用户池作为具有客户端凭据的身份提供者仅在保存到 aws 控制台后才有效的主要内容,如果未能解决你的问题,请参考以下文章
Appsync Cognito 用户池使用 OIDC 提供商登录
AWS Cognito 用户池 + 用于身份验证/登录的社交提供商
如何使用 cognito 身份 id 获取用户属性(用户名、电子邮件等)