0

I am looking into using amazon-cognito-identity-js with my React frontend and boto3 with my Python backend. Once I have a user signed in on the frontend, how can I send an API request to my backend and have the backend verify that the user is signed in before giving data back?

Is it the ID, access or refresh token? If so are these JWT tokens that require a separate library to verify? Or can it be verified within boto3 to check the user's session is active?

Jahill
  • 78
  • 1
  • 7
  • You could look into using aws amplify with React as it makes it easy to do this – chyke007 Jul 21 '23 at 15:43
  • @chyke007 My problem is less with the React side and more with the Python side in verifying users for API endpoints. – Jahill Jul 21 '23 at 18:43
  • I am guessing the python code is a lambda function and is accessed via API gateway. You could add an authorization to use cognito – chyke007 Jul 21 '23 at 20:55
  • @chyke007 I'm not quite sure what you mean by adding an authorization. (My backend in Flask by the way.) – Jahill Jul 24 '23 at 13:15

1 Answers1

0

This is an example using the serverless framework, here the API endpoint is secured using the Cognito User pool.

getUsers:
        handler: src/functions/cognito/get-users.handler
        events:
          - http: 
              path: get-users-data
              method: get
              cors: true
              private: true
              authorizer:
                name: CognitoAuthorizer
                type: COGNITO_USER_POOLS
                arn:
                  Fn::GetAtt: [FacialVoteUserPool, Arn]

Then you just need to add this jwt token you got when user authenticated to the header and send the request to the server

 'Authorization': `Bearer ${jwt}`
chyke007
  • 1,478
  • 1
  • 8
  • 16