使用用户名和密码从后端调用一些 Cognito API
它可以自动调用配置的用户池联合身份
提供者对用户进行身份验证,然后生成 JWT 令牌。如果
是的,请您参考/指导我。
这是可能的。您可以结合使用以下两个参考。
Receiving the JWT token from Cognito UserPools
var authenticationData = {
Username : 'username',
Password : 'password',
};
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
var poolData = { UserPoolId : 'us-east-1_xxxxx',
ClientId : 'xxxxxxxxxxxxxxxx'
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username : 'username',
Pool : userPool
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
/*Use the idToken for Logins Map when Federating User Pools with identity pools or when passing through an Authorization Header to an API Gateway Authorizer*/
console.log('idToken + ' + result.idToken.jwtToken);
},
onFailure: function(err) {
alert(err);
},
});
将 JWT 令牌传递给 Cognito Federated Identity Pool via SDK 并交换 AWS 临时访问凭证,以针对 AWS 配置执行任何操作。
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:xxxxxxx-xxxx-xxxx-xxxx-xxxxxx',
Logins: {
'cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxx': result.idToken.jwtToken
}
});
身份提供商中存在的用户在 AWS 用户池中不存在。是
可以使用配置的身份提供者对用户进行身份验证
没有用户出现在 AWS 用户池中?如果是,那么将
身份验证后在 AWS 用户池中创建用户?
这只有在您的外部身份提供者支持 SAML 联合时才有可能。