generated from cepdnaclk/eYY-3yp-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from lahirumenik/main
tested lambda auth sigin to fetch access token
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const AWS = require('aws-sdk'); | ||
const cognito = new AWS.CognitoIdentityServiceProvider(); | ||
|
||
exports.handler = async (event, context, callback) => { | ||
// Process authentication request | ||
// Use Cognito API to authenticate the user | ||
const cognitoResponse = await cognito.initiateAuth({ | ||
AuthFlow: 'USER_PASSWORD_AUTH', | ||
AuthParameters: { | ||
Username: event.username, | ||
Password: event.password, | ||
}, | ||
ClientId: '1q2aum3ptjv1hpb4u3spldal8r', | ||
}).promise(); | ||
|
||
// Generate access token | ||
const accessToken = cognitoResponse.AuthenticationResult.AccessToken; | ||
|
||
// Include the access token in the response | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ accessToken }), | ||
}; | ||
} |