angular - Angular / AWS Cognito 用户登录错误-“凭据”类型上不存在属性“刷新”
问题描述
我正在尝试为我的 Angular 7 应用程序配置用户登录,并且已经构建了大部分cognitoUser.authenticateUser()
方法,但是在该onSuccess()
方法中,我无法刷新 AWS 配置凭据,因为我在以下位置收到以下错误AWS.config.credentials.refresh()
:
“'Credentials | CredentialsOptions' 类型上不存在属性 'refresh'。'CredentialsOptions' 类型上不存在属性 'refresh'。”
auth.service.ts:
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import * as AWS from 'AWS-sdk';
import { CognitoIdentityCredentials } from 'AWS-sdk';
import * as AmazonCognitoIdentity from 'amazon-cognito-identity-js';
import credentials from '../../../../server/credentials.json';
@Injectable({
providedIn: 'root'
})
export class AuthService {
user: AmazonCognitoIdentity.CognitoUser;
userPool;
userData;
isAuthenticated: boolean;
constructor(private router: Router) {
const poolData = {
UserPoolId: '*****',
ClientId: credentials.appClientId
}
this.userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
if (this.user) {
this.isAuthenticated = true;
} else {
this.isAuthenticated = false;
}
}
signIn(email, password) {
const authDetails = new AmazonCognitoIdentity.AuthenticationDetails({
Username: email,
Password: password
})
const userData = {
Username: email,
Pool: this.userPool
}
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authDetails, {
onSuccess: function(res) {
const accessToken = res.getAccessToken().getJwtToken();
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: this.userPool.UserPoolId,
Logins: {
'cognito-idp.*****.amazonaws.com/*****': res.getIdToken().getJwtToken()
}
})
AWS.config.credentials.refresh(err => {
// ISSUE HERE
})
},
onFailure: function(err) {
}
}
}
}
解决方案
AWS.config.credentials.refresh(err => {
// ISSUE HERE
})
用这个替换上面的代码
( < AWS.CognitoIdentityCredentials > AWS.config.credentials).refresh((error) => {
});
这称为变量转换
推荐阅读
- java - Dialogflow Rest API“没有 OAuth 的服务帐户授权”失败
- javascript - 聚合物未使用聚合物服务加载 ts Web 组件
- java - 如何按顺序连接到 BluetoothGatt 设备的正确方法
- javascript - 如何使用响应式表单动态设置单选按钮文本?并选择*单选按钮值和问题标题* onSubmit
- android - 通过并行whatsapp发送消息到未保存的号码
- php - 从 HTML 表单的动态选择选项中删除重复数据
- javascript - 让索引在 for 循环中一次运行一个
- node.js - 在 Centos 6.8 中使用 Chef 安装 nodejs LTS
- ios - 使用未解析的标识符“UIBezierPath”
- python - 为 SQL 使用 Python 扩展时遇到问题