Code Monkey home page Code Monkey logo

rgparkins / cognito-demo-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arronharden/cognito-demo-service

0.0 1.0 0.0 68 KB

Example Express based REST API in Node.js for my medium.com article on using the AWS Cognito provided JWT tokens in a backend service. Demonstrates downloading of the Cognito JWKS certificates and use of a JWT decoder to verify the claims in a JWT token, all wrapped up in a reusable Express middleware function.

Home Page: https://medium.com/@arron.harden/aws-cognito-example-using-react-ui-and-node-js-rest-apis-part-3-jwt-secured-rest-apis-e56d336ce306

License: MIT License

JavaScript 97.10% HTML 1.78% CSS 1.12%

cognito-demo-service's Introduction

This application was created using the create express component, and demonstrates how to verify the JWT authentication tokens used by AWS Cognito in an express based node.js service. See my article AWS Cognito example using React UI and Node.js REST APIs โ€” part 3 (JWT secured REST APIs) for more information.

Running the application

  1. Modify src/config/app-config.json to match your user pool and application URLs. When running locally with the UI, the signoutUri will property need to be http://localhost:3000/ and the callbackUri property will need to be http://localhost:3000/callback.
  2. Run npm install to setup and install the dependencies.
  3. Run DEBUG=cognito-demo-service:* npm start to start the service.
  4. The service will start listening at http:localhost:3010.
  5. Using curl call the GET /users REST API:
curl -X GET http://localhost:3010/users -H 'Authorization: Bearer <your_JWT_token>'

and if successful you should see the following type of response:

Successfully verified JWT token. Extracted information: {"sub":"1f0be62f-ffcd-49ca-b5a4-18f0bf62e0e6","token_use":"access","scope":["openid","profile","https://cognito-demo-api.arronharden.com/hello-world.all","email"],"username":"arron"}

React UI client

The source for an example React UI application which invokes this REST API is contained in the repo at https://github.com/arronharden/cognito-demo-ui. A running instance of this React application is hosted at https://cognito-demo.arronharden.com.

Example

A running instance of this REST API is hosted at https://cognito-demo-api.arronharden.com.

About me

I'm a cloud/SaaS architect and lead full stack engineer, living in Milton Keynes (UK). More information about me can be found on my profile at https://arronharden.com.

cognito-demo-service's People

Contributors

arronharden avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.