【问题标题】:Amplify get owner user attributes from Cognito放大从 Cognito 获取所有者用户属性
【发布时间】:2020-10-25 14:49:27
【问题描述】:

背景: 我正在使用 Amplify 创建一个带有 @auth allow ownertype Item @model GraphQL 数据存储,它将所有者作为 CognitoID 添加到项目中。

问题: 此项目可供客人阅读,我想显示此项目的所有者(或其他相关元数据,如用户名/电子邮件)。

例如Cognito.GetUserAttributes(2b10fb7e-4472-43c9-9bb9-54219b5027a3)

这样的事情可能吗?这应该如何为这个用例设计?我是否必须添加一个 lambda,以便在创建项目时将用户元数据添加到项目中?

我希望此解决方案具有可扩展性。


架构:

type Item
@model
@auth(rules: [
    { allow: owner},
    { allow: groups, groups: ["Admin"] },
    { allow: private, operations: [read] },
    { allow: public, operations: [read] }
])
{
    id: ID!
    title: String!
    description: String
}

来自 DynamoDB:

{
  "__typename": "Item",
  "_lastChangedAt": 1593707126605,
  "_version": 1,
  "createdAt": "2020-07-02T16:25:26.582Z",
  "description": "Description",
  "id": "0592fcd8-408e-406e-84bf-9f63eb43e147",
  "owner": "2b10fb7e-4472-43c9-9bb9-54219b5027a3",
  "title": "Item",
  "updatedAt": "2020-07-02T16:25:26.582Z"
}

【问题讨论】:

    标签: amazon-web-services amazon-cognito aws-amplify


    【解决方案1】:

    您可以在cognitoAttributes 字段上使用函数解析器。 lambda函数可以调用Cognito中的admin-get-user并返回属性。 lambda 函数将接收 event.source 属性中的发电机项,因此您将有权访问所有者 ID 以调用 Cognito

    type Item
    @model
    @auth(rules: [
        { allow: owner},
        { allow: groups, groups: ["Admin"] },
        { allow: private, operations: [read] },
        { allow: public, operations: [read] }
    ])
    {
        id: ID!
        title: String!
        cognitoAttributes: [String]! @function('cognitoGetUserAttributes-${env})
        description: String
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-09
      • 2023-02-13
      • 2022-11-22
      • 2021-05-06
      • 1970-01-01
      • 2017-08-12
      • 2016-12-31
      • 2019-07-22
      相关资源
      最近更新 更多