Create an OAuth Client-Server for code/token exchange

Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

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.

egghead
egghead
~ 2 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today