使用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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...