简体   繁体   English

AppSync 与多个 Cognito 用户池

[英]AppSync with multiple Cognito User Pools

I am working on an Amplify application with AppSync GraphQL as API.我正在使用 AppSync GraphQL 作为 API 处理 Amplify 应用程序。

I am trying to have 2 separate user pools that can be used as authentication sources for this GraphQL API.我正在尝试拥有 2 个单独的用户池,可用作此 GraphQL API 的身份验证源。

Following the Amplify tutorial, I was able to deploy the AppSync GraphQL API, but there is no option for me to configure multiple user pools.按照 Amplify 教程,我能够部署 AppSync GraphQL API,但我没有配置多个用户池的选项。

I looked into the AWS Console and saw that I can add more User Pools under "Additional authorization providers", but when I did then tried it out in Query section, only the first User Pool works.我查看了 AWS 控制台,发现我可以在“其他授权提供商”下添加更多用户池,但是当我在查询部分尝试时,只有第一个用户池有效。 The API responded with API 回复了

"message": "Not Authorized to access listTodos on type Query"

Here is my schema:这是我的模式:

type Todo @model {
  id: ID!
  name: String!
  description: String
}

I also tried to add the second User Pools as Authentication Provider for the Identity Pool generated by Amplify, no luck as well.我还尝试将第二个用户池添加为 Amplify 生成的身份池的身份验证提供者,但也不走运。

Is it possible to use 2 User Pools in a single AppSync API?是否可以在单个 AppSync API 中使用 2 个用户池? What am I missing here?我在这里错过了什么?

Thanks.谢谢。

I was facing the same problem but.我遇到了同样的问题但是。 Finally I figured it out.最后我想通了。

you have to add extra directives to your schema with multiple authorizations.您必须使用多个授权向您的模式添加额外的指令。 In your case, you should update your schema as follows:在您的情况下,您应该按如下方式更新架构:

type Todo @model @aws_cognito_user_pools {
  id: ID!
  name: String!
  description: String
}

You can find more information about this from here: https://aws.amazon.com/blogs/mobile/using-multiple-authorization-types-with-aws-appsync-graphql-apis/您可以从此处找到更多相关信息: https://aws.amazon.com/blogs/mobile/using-multiple-authorization-types-with-aws-appsync-graphql-apis/

@Mahmoud Watidy how to specify which pool to be used among 2 for this type here: @Mahmoud Watidy 如何在此处指定要在 2 中使用哪个池:

type Todo @model @aws_cognito_user_pools { id: ID: name: String!输入 Todo @model @aws_cognito_user_pools { id: ID: name: String! description: String }描述:字符串}

I mean how this shows that pool1 is used or pool2 is used for aut?我的意思是这如何表明使用 pool1 或 pool2 用于 aut?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM