Code Monkey home page Code Monkey logo

jwt-server-to-server's Introduction

JWT server to server communication in Node.js

About

This repository is the source code for the JWT server to server communication in Node.js tutorial series on Youtube on YouTube provided by productioncoder.com.

Please help this repo with a โญ๏ธ if you find it useful! ๐Ÿ˜

JWT server to server communication

For updates, please follow @_jgoebel on Twitter.

2 How to run this application

2.1 Install dependencies

Install the dependencies by running

npm install

2.2 HMAC communication

To initiate an HMAC server to server communication, you need to spin up two server so they can talk to each other

We recommend opening two terminal windows for this. In the first terminal run

npm run serverA

In the second terminal window run:

npm run serverB

You now have two servers running on port 3000 and on port 8080.

2.3. RSA-based server to server communication

Make sure that you create two RSA keypairs and paste it in the root directory with the following file names

serverA-private.key
serverA-public.key
serverB-private.key
serverB-public.key

If you do not want to generate an RSA keypair with openssl via the command line, you can use an online service like jsencrypt if you just want to try out the project locally.

2.4. Let the servers talk to each other

To let one server send a message to the other server, you can hit the following unprotected REST endpoint with curl or with Postman:

POST localhost:8080/produce

Note that both servers support the POST /produce endpoint. Therfore, you can also hit

POST localhost:3000/produce

Both servers will not print log messages that indicate that they just exchanged information with JWT tokens in the header.

3 Security

To make this communcation truly secure, we would need to make use of a secure transport protocol such as https.

Since this is a tutorial and we did not want to complicate it further by using self-signed certificates, we just use http for the sake of simplicity.

We do this, so the tutorial is easier to understand. In a _production scenario you need to use a secure protocol such as https / TLS to ensure a secure communication.

jwt-server-to-server's People

Contributors

jangbl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

gsathishkumar

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.