Create an OAuth Client-Server for code/token exchange

Share this video with your friends

Social Share Links

Send Tweet

We'll create our client-server using the express and cors packages

Express will be used to create our HTTP application. We'll need it to post to our endpoints and listen to our port.

We need the cors package to make cross-origin requests since the front-end will be a different origin than the server.

Instructor: [0:00] Open the index.js file inside the server folder. Import express which we will use to create a HTTP application. Import cause which we can use to enable cross origin requests, since the frontend will be a different origin from the server. Now, go ahead and create an express app. Add a middle word to the app that configures cause.

[0:29] Add another middle word to parse requested body data to JSON. Create a slash code post endpoint and for now it should respond with the request body. Now, set up the express app to listen at port 1,235. You can use any HTTP client to test the endpoint.

[0:58] If you have the VS Code REST client extension, add a test.http file in the server folder. Open the file in the editor and set the request method as well as the URL. Set the content type to application slash JSON.

[1:18] Finally, create a body and set the code property to any string value. Click, send request, and you should see the response, a code block, in the output.