【问题标题】:Access Existing AWS Cognito UserPool (which I am not the owner of) using UserPoolId & ClientId keys with Angular Application使用带有 Angular 应用程序的 UserPoolId 和 ClientId 键访问现有的 AWS Cognito UserPool(我不是其所有者)
【发布时间】:2020-05-21 16:01:26
【问题描述】:

我被要求进行编码挑战并构建一个使用 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 authentication amazon-cognito


    【解决方案1】:

    Joshua 在我在 medium 上的演示中,我只是硬编码了参数。但您也可以将它们放在 Angular 的环境文件中,然后将它们映射到用于初始化 SDK 的用户池对象。 Here's a link to an article on the environment files.

    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:
    
    

    从'../environments/environment'导入{环境};

    
    And you would configure the userpoolID in the environment file:
    
    

    导出常量环境 = { UserPoolId: '您的用户池 ID', ClientId: '您的客户 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
    
    
    

    【讨论】:

    • 嗨@Ole,非常感谢您回复我。我现在就试一试,然后告诉你。
    • 从“amazon-cognito-identity-js”导入{CognitoUserPool}; - 你把它放在哪个文件中?,user-authentification.component.ts(和仪表板?)或其他地方放在一起
    • 我也能够在没有硬编码任何参数的情况下跟随你的媒体演示,所以我不知道你在哪里做的......
    • 我现在也写过这个问题:stackoverflow.com/questions/60101611/…
    猜你喜欢
    • 2017-07-12
    • 2020-01-23
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 2012-12-15
    • 2014-07-24
    相关资源
    最近更新 更多