From 6fa413f460368ac247ab87d606b1088c2cdfec8b Mon Sep 17 00:00:00 2001 From: lahirumenik <115687865+lahirumenik@users.noreply.github.com> Date: Sun, 7 Jan 2024 00:48:10 +0530 Subject: [PATCH] tested lambda auth sigin to fetch access token --- backend/serverless/testing/siginauth.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 backend/serverless/testing/siginauth.js diff --git a/backend/serverless/testing/siginauth.js b/backend/serverless/testing/siginauth.js new file mode 100644 index 0000000..d566996 --- /dev/null +++ b/backend/serverless/testing/siginauth.js @@ -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 }), + }; +} \ No newline at end of file