PeterN
PeterN

Reputation: 2177

Finishing AWS authentication flow

TLDR I am looking for somewhere to send cognito JWT's from the backend to verify the user's status.


I currently have a react app, with a serverless apollo api, and dynamodb database, all running locally.

So far I cannot find where to send the tokens from the backend, to verify that the user is signed in to cognito. I have scoured the docs but TBH that has left me more confused.

As far as I can understand, in production API Gateway, or AppSync can intecept the tokens between the front and backend, but since I have verified tokens at the backend currently is there an endpoint or SDK method I can hit with tokens/ access keys etc to check the users status?

Feel free to tell me if I'm going about this the wrong way.

Upvotes: 1

Views: 134

Answers (1)

Joey Kilpatrick
Joey Kilpatrick

Reputation: 1602

If you need to verify that a token is valid and unexpired, with the JavaScript SDK use

const cognitoServiceProvider = new AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});
await cognitoServiceProvider.getUser({
        AccessToken: accessToken
    }).promise();

This will throw an error if the token is not valid.

If you are using a different SDK, find the equivalent call.

Upvotes: 2

Related Questions