如何使用 AWS Cognito 中的现有用户池生成 aws-exports.js?
Posted
技术标签:
【中文标题】如何使用 AWS Cognito 中的现有用户池生成 aws-exports.js?【英文标题】:How to generate aws-exports.js with existing User Pool in AWS Cognito? 【发布时间】:2019-10-21 02:24:27 【问题描述】:我无法使用 AWS Cognito 的现有用户池生成 aws-exports.js 文件。怎么做?
我尝试通过创建 AWS Cognito 的新用户池来生成 aws-exports.js 文件。但这不是我想要的正确的事情。另外,我在github上找到了一些问题的解释:https://github.com/aws-amplify/amplify-cli/issues/779#issuecomment-458080804
【问题讨论】:
你读过这个吗? medium.com/@danielcender/… 应该有帮助。 【参考方案1】:来自this page in the docs:
如果您想重复使用 AWS 中的现有身份验证资源(例如 Amazon Cognito 用户池或身份池),请使用以下信息更新 Amplify.configure() 方法。
import Amplify, Auth from 'aws-amplify';
Amplify.configure(
Auth:
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
// REQUIRED - Amazon Cognito Region
region: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito Federated Identity Pool Region
// Required only if it's different from Amazon Cognito Region
identityPoolRegion: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'XX-XXXX-X_abcd1234',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
// OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: false,
// OPTIONAL - Configuration for cookie storage
// Note: if the secure flag is set to true, then the cookie transmission requires a secure protocol
cookieStorage:
// REQUIRED - Cookie domain (only required if cookieStorage is provided)
domain: '.yourdomain.com',
// OPTIONAL - Cookie path
path: '/',
// OPTIONAL - Cookie expiration in days
expires: 365,
// OPTIONAL - See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
sameSite: "strict" | "lax",
// OPTIONAL - Cookie secure flag
// Either true or false, indicating if the cookie transmission requires a secure protocol (https).
secure: true
,
// OPTIONAL - customized storage object
storage: MyStorage,
// OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_PASSWORD_AUTH',
// OPTIONAL - Manually set key value pairs that can be passed to Cognito Lambda Triggers
clientMetadata: myCustomKey: 'myCustomValue' ,
// OPTIONAL - Hosted UI configuration
oauth:
domain: 'your_cognito_domain',
scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
redirectSignIn: 'http://localhost:3000/',
redirectSignOut: 'http://localhost:3000/',
responseType: 'code' // or 'token', note that REFRESH token will only be generated when the responseType is code
);
// You can get the current config object
const currentConfig = Auth.configure();
【讨论】:
【参考方案2】:你可以这样做: 放大。配置( 授权: identityPoolId: 'xxxxxx', 地区:'xxxxx', userPoolId: 'xxxxxxx', userPoolWebClientId: 'xxxxx' );
【讨论】:
您能否在答案中添加更多信息?答案看起来不像尝试生成文件。以上是关于如何使用 AWS Cognito 中的现有用户池生成 aws-exports.js?的主要内容,如果未能解决你的问题,请参考以下文章
将 Cognito 中的用户信息与 AWS Amplify GraphQL 关联