如何解决使用amazon-cognito-identity-js javascript获取idToken
我想访问需要有效idToken的Codefi Compliance API端点,可以使用amazon-cognito-identity-js进行获取。
我尝试使用此代码,但收到错误index.js:3 Uncaught ReferenceError:未定义导出
<html>
<head>
<title>Max</title>
<html>
<head>
<title>Max</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/node-fetch@2.6.0/browser.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/amazon-cognito-identity-js@4.3.4/lib/index.min.js"></script>
<script>
global.fetch = require('node-fetch');
var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
global.navigator = () => null;
global.fetch = require('node-fetch');
var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
var authenticationData = {
Username : 'YOUR_USERNAME',Password : 'YOUR_PASSWRD',};
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
var poolData = { UserPoolId : 'us-east-1_22Qg1ksxH',ClientId : '19dph7p79mhboibih2b9qk4j9p'
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username : 'YOUR_USERNAME',Pool : userPool
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails,{
onSuccess: function (result) {
/* 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*/
var idToken = result.idToken.jwtToken;
console.log('idToken:',idToken);
},onFailure: function(err) {
console.error('ERRR: ',err);
},});
</script>
</body>
</html>
</head>
<body>
<script>
global.fetch = require('node-fetch');
var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
global.navigator = () => null;
global.fetch = require('node-fetch');
var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
var authenticationData = {
Username : 'YOUR_USERNAME',ClientId : '19dph7p79mhboibih2b9qk4j9p'
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username : 'YOUR_USERNAME',{
onSuccess: function (result) {
/* 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*/
var idToken = result.idToken.jwtToken;
console.log('idToken:',idToken);
},onFailure: function(err) {
console.error('ERRR: ',});
</script>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。