-
-
Save eks1985/5a51a557802f2af8a4204e4b925360f0 to your computer and use it in GitHub Desktop.
aws
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
const login = () => { | |
let Username = 'reacttest'; | |
let Password = 'reacttest'; | |
let authenticationDetails = new AuthenticationDetails({ | |
Username, | |
Password | |
}); | |
const { UserPoolId, ClientId } = config; | |
var poolData = { UserPoolId, ClientId }; | |
var userPool = new CognitoUserPool(poolData); | |
var userData = { | |
Username : 'reacttest', | |
Pool : userPool | |
}; | |
var cognitoUser = new CognitoUser(userData); | |
cognitoUser.authenticateUser(authenticationDetails, { | |
onSuccess: function (result) { | |
AWS.config.credentials = new AWS.CognitoIdentityCredentials({ | |
IdentityPoolId : config.IdentityPoolId, // your identity pool id here | |
Logins : { | |
['cognito-idp.' + config.region + '.amazonaws.com/' + config.UserPoolId] : result.getIdToken().getJwtToken() | |
} | |
}); | |
// var additionalParams = { | |
// headers: { | |
// "Access-Control-Allow-Origin": "*", | |
// "Access-Control-Allow-Methods": "GET,OPTIONS", | |
// // "Access-Control-Allow-Headers": "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token", | |
// "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept" | |
// | |
// }, | |
// }; | |
AWS.config.credentials.get(function() { | |
console.log('AWS.config', AWS.config.credentials); | |
var apigClient = window.apigClientFactory.newClient({ | |
accessKey: AWS.config.credentials.accessKeyId, | |
secretKey: AWS.config.credentials.secretAccessKey, | |
sessionToken: AWS.config.sessionToken, | |
region: config.region | |
}); | |
apigClient.identityGet({}, '', {}); | |
}); | |
}, | |
onFailure: function(err) { | |
alert(err); | |
}, | |
}); | |
}; | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment