使用对象在 AWS Cognito 用户池中设置地址属性

问题描述 投票:0回答:1

根据文档,Cognito“地址”属性应遵循OpenID规范,它允许具有字段的对象:

formatted
    Full mailing address, formatted for display or use on a mailing label. This field MAY contain multiple lines, separated by newlines. Newlines can be represented either as a carriage return/line feed pair ("\r\n") or as a single line feed character ("\n"). 
street_address
    Full street address component, which MAY include house number, street name, Post Office Box, and multi-line extended street address information. This field MAY contain multiple lines, separated by newlines. Newlines can be represented either as a carriage return/line feed pair ("\r\n") or as a single line feed character ("\n"). 
locality
    City or locality component. 
region
    State, province, prefecture, or region component. 
postal_code
    Zip code or postal code component. 
country
    Country name component. 

Cognito 中可以设置这些字段吗?我尝试使用字符串化对象设置地址,即

JSON.stringify({"locality": "Auckland", "country": "New Zealand"})
。但是,当我从 AWS API 网关的授权返回声明对象时,我得到了
address: { formatted: '{"locality":"Auckland","country":"New Zealand"}' }
。所以看起来它只是采用我发送的任何字符串并将其设置为“格式化”地址。

我正在使用 Amplify Auth api 与 cognito 交互。

amazon-web-services amazon-cognito aws-amplify
1个回答
0
投票

我在这里发帖以防万一有人遇到这个问题。

对我来说有效的方法涉及通过 UpdateUserAttributesCommand 命令发送用户属性,如下

[
  { Name: 'given_name', Value: 'John' },
  { Name: 'family_name', Value: 'Doe' },
  { Name: 'birthdate', Value: '1990-01-01' },
  {
    Name: 'address',
    Value: '{"country":"United States","city":"New York","postal_code":"10001","street_address":"123"}'
  }
]

这会在 AWS 控制台中产生以下输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.