在Angular 2中实现AWS-Cognito
我目前正在尝试使用Angular和AWS构建Web应用程序.我的第一步是使用AWS-Cognito进行工作身份验证.但是我在使用AWS-Cognito SDK时遇到了一些问题.
我采取了以下步骤: 我开始使用这个Angular 2快速入门来设置我的应用程序:https://github.com/angular/quickstart,然后运行npm install 我的下一步是使用npm install -g @ angular / cli安装angular CLI 接下来我通过运行安装angular-cognito-identity-sdk:npm install –save amazon-cognito-identity-js 安装SDK后,我需要将sdk放入我的组件中: console.log(AmazonCognitoIdentity); var authenticationData = { Username : 'username',Password : 'password',}; var authenticationDetails = new AmazonCognitoIdentity.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData); var poolData = { UserPoolId : 'pool_id',// Your user pool id here ClientId : 'client_id' // Your client id here }; var userPool = new AmazonCognitoIdentity.CognitoIdentityServiceProvider.CognitoUserPool(poolData); var userData = { Username : 'username',Pool : userPool }; 但是当我运行代码时,I?m给出了以下错误:
我在这里错过了一步吗?在我的Angular应用程序中实现Cognito SDK的最佳方法是什么? 谢谢! 解决方法
删除CognitoIdentityServiceProvider.例如:
import * as AWSCognito from 'amazon-cognito-identity-js'; // Later on const userPool = new AWSCognito.CognitoUserPool(awsCognitoSettings); const authDetails = new AWSCognito.AuthenticationDetails({ Username: this.state.username,Password: this.state.password }); const cognitoUser = new AWSCognito.CognitoUser({ Username: this.state.username,Pool: userPool }); cognitoUser.authenticateUser(authDetails,{ onSuccess: (result) => { console.log(`access token = ${result.getAccessToken().getJwtToken()}`); },onFailure: (err) => { alert(err); } }); CognitoIdentityServiceProvider是aws-sdk的一部分,而不是amazon-cognito-identity-js库. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |