我想要做的是將API網關設置爲我的Lambda函數,該函數將一些內容保存在DynamoDB中(或其他我只想登錄用戶的東西)。但我不明白如何驗證AccessToken以及如何從中獲取用戶。如何在AWS Lambda中驗證Cognito訪問令牌以允許網關API調用?
我發現這個post在AWS上論壇,我決定嘗試方法1.
Cognito用戶池+ API網關+ API網關定製認證器+ Cognito用戶池訪問令牌。
所以,現在我已經登錄的用戶:
var authenticationData = {
Username : 'username', // your username here
Password : 'password', // your password here
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
....
和他的accessToken。我還在API調用中設置了自定義API網關自定義授權者。
現在我應該驗證訪問令牌並決定是允許還是拒絕方法調用。但我不明白如何做到這一點,以及如何從令牌中檢索用戶?
謝謝,這有很大的幫助。 – wonglik
正是我需要的,謝謝! –