通过 Angular 应用程序使用 UserPoolId 和 ClientId 密钥访问现有的 AWS Cognito UserPool(我不是其所有者)



我被要求做一个编码挑战,并构建一个使用 AWS Cognito 进行身份验证的小应用程序。

我一直在提供以下密钥:

UserPoolId: "us-east-1_dJfLT4QIp"
ClientId: "194t5jewd8o56ppmbjjlvdt6yi"

(不是真正的细节(。

我可以轻松地遵循本教程:https://medium.com/better-programming/create-a-fully-functioning-user-authentication-with-aws-cognito-and-amplify-with-angular-complete-a3ce58df1b74

从没有AWS账户到使用AWS Cognito登录,但是我不明白如何将提供给我的密钥集成到我的应用程序中。

是否可以在我的应用程序中的某个位置设置这些密钥以访问预先存在的用户池?

这是我目前最有希望的道路:https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html

约书亚 在我有的演示中,我只是硬编码了参数。 但您也可以将它们放在 Angular 的环境文件中,然后将它们映射到您用来初始化 SDK 的用户池对象。 这是一篇关于环境文件的文章的链接。

import {CognitoUserPool} from 'amazon-cognito-identity-js';
const PC = {
UserPoolId: 'Your user pool id',
ClientId: 'Your Client ID'
};
const userPool = new CognitoUserPool(PC);
So if you have the parameters in your environment then you would import that:

从 '.. 导入 { 环境 }/环境/环境";


And you would configure the userpoolID in the environment file:

导出常量环境 = { 用户池 ID:"您的用户池 ID", 客户 ID:"您的客户 ID" };


If these are the only keys you can pass the entire imported environment to the SDK:
const userPool = new CognitoUserPool(environment);

I also wrote an article on how to setup Cognito using AWS Amplify and Google federated identities, so you can have a look at that an see how the amplify exports are imported:
https://medium.com/@ole.ersoy/adding-aws-cognito-federated-login-with-google-using-aws-amplify-78bf68f19c68

最新更新