{"id":19255,"date":"2017-11-27T09:00:16","date_gmt":"2017-11-27T07:00:16","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=19255"},"modified":"2017-12-09T11:58:23","modified_gmt":"2017-12-09T09:58:23","slug":"secure-node-js-website-openid-connect","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/","title":{"rendered":"Secure Your Node.js Website with OpenID Connect"},"content":{"rendered":"<p><span style=\"font-size: 20px;\"><b>\u201cI love writing authentication and authorization code.\u201d ~ No Web Developer Ever.<\/b> Tired of building the same login screens over and over? <a href=\"https:\/\/developer.okta.com\/signup\/?utm_campaign=Syndication%3EGlobal%3Eopenid-connect-build-simple-node-website-FY18Q4&amp;utm_medium=post&amp;utm_source=web-code-geeks-all-developer\">Try the Okta API for hosted authentication, authorization, and multi-factor auth.<\/a> <\/span><\/p>\n<p>User authentication in Node can be confusing. It\u2019s confusing for lots of people, including really talented Node developers, so you\u2019re not alone. Authentication practices change frequently and can be hard to keep up with. In this tutorial, I\u2019m going to show you how to use OpenID Connect to build an extremely simple Node.js website (using Express.js) that allows you to manage your users, log them in, and log them out.<\/p>\n<p>Back in the day, all websites would require users to register with a username\/password and log in with those same credentials. This was simple, but caused a lot of security problems because developers would need to write the code to authenticate the user directly, store their credentials, manage their data, etc. It also required developers to build custom authorization schemes so that they could track what permissions their users had to perform certain operations.<\/p>\n<p>A while later, OAuth came into fashion with a new idea: let a user have one account with a large OAuth provider (Google, Facebook, etc.), and let users log into your service via their OAuth account with that provider. This had some nice benefits: developers no longer had to worry about storing passwords and managing credentials. The downside was that OAuth is a flexible protocol, and doesn\u2019t lay out rules around authorization, data management, etc. This means that developers using pure OAuth are required to write a lot of custom security code themselves, which causes problems.<\/p>\n<p>Just recently, however,\u00a0<a href=\"http:\/\/openid.net\/connect\/\">OpenID Connect<\/a>\u00a0(OIDC) has come onto the scene. It\u2019s a protocol built on top of OAuth that provides everything you could ever want: simplified user authentication, simplified authorization, and lots of nice management to tie them all together. OIDC has been gaining popularity in the development community.<\/p>\n<p>The only problem with OIDC is that there still aren\u2019t a ton of great tools and integrations to make using it easy.<\/p>\n<p>One of my amazing\u00a0<a href=\"https:\/\/developer.okta.com\/\">Okta<\/a>\u00a0colleagues,\u00a0<a href=\"https:\/\/github.com\/robertjd\">Robert<\/a>, has been working on a new Node.js library,\u00a0<a href=\"https:\/\/www.npmjs.com\/package\/@okta\/oidc-middleware#customizing-routes\">oidc-middleware<\/a>, that attempts to make adding user authentication and authorization to your Node apps simple.<\/p>\n<p>So, without further ado, let\u2019s build something together! I\u2019ll show you how to use the new oidc-middleware package to build a simple website.<\/p>\n<h2 id=\"create-an-okta-account\">Create an Okta Account<\/h2>\n<p>The first thing you\u2019ll need to do before we build our simple Node.js website is to create a free\u00a0<a href=\"https:\/\/developer.okta.com\/signup\/\">Okta developer account<\/a>.<\/p>\n<p>If you haven\u2019t heard of Okta before, we\u2019re an API service that allows you to easily store your user accounts, manage them from a simple web UI, handle user login and registration, password reset functionality, social login, single sign-on, and lots more.<\/p>\n<p><strong>NOTE<\/strong>: If you\u2019d like to skip the following sections and get straight into the code, you can visit the\u00a0<a href=\"https:\/\/github.com\/oktadeveloper\/okta-express-example\">Github repo<\/a>\u00a0for this application directly.<\/p>\n<h2 id=\"create-an-application\">Create an Application<\/h2>\n<p>Now that you\u2019ve got an Okta account, you need to create an Application. Using Okta, you can create as many Applications as you\u2019d like. Each Application represents an actual application you might be building.<\/p>\n<p>Since you\u2019re going to be building a simple Node website right now, you only need to create a single Application.<\/p>\n<p>To get started, go log into your new Okta dashboard. Once you\u2019re in, click the \u201cApplications\u201d tab. You\u2019ll see something like this:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/1.png\"><img decoding=\"async\" class=\"aligncenter wp-image-19256\" style=\"border: none;\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/1.png\" alt=\"\" width=\"860\" height=\"469\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/1.png 1440w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/1-300x164.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/1-768x419.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/1-1024x559.png 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>This is where you can view all of your Okta applications, and manage them.<\/p>\n<p>Since we don\u2019t have an Application created yet, let\u2019s do that now. Click the big green \u201cAdd Application\u201d button and then click the \u201cWeb\u201d box (because you\u2019re going to build a web app):<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/2.png\"><img decoding=\"async\" class=\"aligncenter wp-image-19257\" style=\"border: none;\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/2.png\" alt=\"\" width=\"860\" height=\"469\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/2.png 1440w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/2-300x164.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/2-768x419.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/2-1024x559.png 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>Once you move to the next screen, you\u2019ll be able to configure your app settings. There\u2019s a lot of things you can do here (feel free to play around with it sometime!), but for now: leave all the defaults as-is.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/3.png\"><img decoding=\"async\" class=\"aligncenter wp-image-19258\" style=\"border: none;\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/3.png\" alt=\"\" width=\"860\" height=\"469\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/3.png 1440w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/3-300x164.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/3-768x419.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/3-1024x559.png 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>Next, you\u2019ll want to copy down a few settings that we\u2019ll need later on.<\/p>\n<p>To start, you\u2019ll need the Client ID and Client Secret of your newly created Application. You\u2019ll find this on the page you land one once you\u2019ve created your new Application:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/4.png\"><img decoding=\"async\" class=\"aligncenter wp-image-19259\" style=\"border: none;\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/4.png\" alt=\"\" width=\"860\" height=\"469\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/4.png 1440w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/4-300x164.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/4-768x419.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/4-1024x559.png 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>Next, you\u2019ll need your Okta Organization URL. If you go to the \u201cDashboard\u201d page, you should see it at the top-right hand corner of the page. It\u2019s the setting called \u201cOrg URL\u201d. Here\u2019s what mine looks like, for example:\u00a0<a class=\"vglnk\" href=\"http:\/\/dev-310095.oktapreview.com\/\" rel=\"nofollow\">dev-310095.oktapreview.com<\/a><\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/5.png\"><img decoding=\"async\" class=\"aligncenter wp-image-19260\" style=\"border: none;\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/5.png\" alt=\"\" width=\"860\" height=\"488\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/5.png 1396w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/5-300x170.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/5-768x436.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/5-1024x581.png 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>Now that you have those settings, keep them someplace safe and we\u2019ll use them soon.<\/p>\n<h2 id=\"build-the-expressjs-app\">Build the Express.js App<\/h2>\n<p>The next thing you\u2019ll do is build a simple Express.js app without any sort of login capabilities. It will be very simple (but that\u2019s the point!).<\/p>\n<h3 id=\"create-the-application-skeleton\">Create the Application Skeleton<\/h3>\n<p>To get started, create a new folder somewhere on your computer, and enter it. Then create a\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">server.js<\/code>\u00a0file and insert the following code:<\/p>\n<pre class=\"gutter: false;brush:bash\">\"use strict\";\r\n\r\nconst express = require(\"express\");\r\n\r\nlet app = express();\r\n\r\n\/\/ App settings\r\napp.set(\"view engine\", \"pug\");\r\n\r\n\/\/ App middleware\r\napp.use(\"\/static\", express.static(\"static\"));\r\n\r\n\/\/ App routes\r\napp.get(\"\/\", (req, res) =&gt; {\r\n  res.render(\"index\");\r\n});\r\n\r\napp.get(\"\/dashboard\", (req, res) =&gt; {\r\n  res.render(\"dashboard\");\r\n});\r\n\r\napp.get(\"\/logout\", (req, res) =&gt; {\r\n  res.redirect(\"\/\");\r\n});\r\n\r\napp.listen(3000);<\/pre>\n<p>This is a basic Express.js application:<\/p>\n<ul>\n<li>It creates an Express application<\/li>\n<li>It configures Express to serve static files (css, images, etc.)<\/li>\n<li>It contains three routes: a home page route, a dashboard route, and a logout route. The home page route simply shows an HTML template (that we\u2019ll create in a moment). The dashboard route shows a dashboard template. And the logout route redirects the user back to the home page. Simple!<\/li>\n<li>On the very last line of the file, Express will start up a local web server on port 3000 so you can view the website locally.<\/li>\n<\/ul>\n<p>Next, you\u2019ll need to create a new directory called\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">views<\/code>, and inside it, create a\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">base.pug<\/code>\u00a0template with the following contents:<\/p>\n<pre class=\"gutter: false;brush:php; wrap-lines:false\">doctype html\r\nhtml(lang=\"en\")\r\n  head\r\n    meta(charset=\"utf-8\")\r\n    meta(name=\"viewport\", content=\"width=device-width, initial-scale=1, shrink-to-fit=no\")\r\n\r\n    link(rel=\"stylesheet\", href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/4.0.0-beta\/css\/bootstrap.min.css\", integrity=\"sha384-\/Y6pD6FV\/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M\", crossorigin=\"anonymous\")\r\n    link(rel=\"stylesheet\", href=\"\/static\/css\/style.css\")\r\n\r\n  body\r\n    .container\r\n      block body\r\n\r\n    script(src=\"https:\/\/code.jquery.com\/jquery-3.2.1.slim.min.js\", integrity=\"sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr\/rE9\/Qpg6aAZGJwFDMVNA\/GpGFF93hXpG5KkN\", crossorigin=\"anonymous\")\r\n    script(src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/popper.js\/1.11.0\/umd\/popper.min.js\", integrity=\"sha384-b\/U6ypiBEHpOf\/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4\", crossorigin=\"anonymous\")\r\n    script(src=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/4.0.0-beta\/js\/bootstrap.min.js\", integrity=\"sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1\", crossorigin=\"anonymous\")<\/pre>\n<p>This is a simple\u00a0<a href=\"https:\/\/pugjs.org\/api\/getting-started.html\">pug<\/a>\u00a0template that contains nothing more than some very basic HTML formatting, and\u00a0<a href=\"http:\/\/getbootstrap.com\/\">Bootstrap<\/a>. If you aren\u2019t already familiar with pug, you may want to read through this\u00a0<a href=\"https:\/\/www.sitepoint.com\/jade-tutorial-for-beginners\/\">excellent beginner\u2019s tutorial<\/a>.<\/p>\n<p><strong>NOTE<\/strong>: pug used to be named\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">jade<\/code>, this is useful to know if you\u2019re looking for resources online.<\/p>\n<p>Next, you\u2019ll want to create the HTML template that renders the home page of the site. Create the file\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">views\/index.pug<\/code>\u00a0and include the following code:<\/p>\n<pre class=\"gutter: false;brush:bash\">extends base.pug\r\n\r\nblock body\r\n  h1.text-center Welcome to the Example App!\r\n\r\n  .jumbotron\r\n    p.\r\n      Thanks for checking out this super simple Okta sample app.  If you login\r\n      below, you'll be taken to an admin panel that is only accessible for\r\n      authenticated users.\r\n\r\n    p.\r\n      Please #[a(href=\"\/login\") login] to continue.<\/pre>\n<p>This is your simple home page template.<\/p>\n<p>Now, let\u2019s create a dashboard page. This page will be what the user sees after logging into the website. Create the file\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">views\/dashboard.pug<\/code>\u00a0and include the following:<\/p>\n<pre class=\"gutter: false;brush:bash\">extends base.pug\r\n\r\nblock body\r\n  h1.text-center User Dashboard\r\n\r\n  .jumbotron\r\n    ul\r\n      li Your Email Address is: #{user.preferred_username}\r\n      li Your First Name is: #{user.given_name}\r\n      li Your Last Name is: #{user.family_name}\r\n\r\n    p.\r\n      If you'd like to logout, please #[a(href=\"\/logout\") click here].<\/pre>\n<p>Next, let\u2019s add a bit of CSS to make things look nice. Create a new folder to store your static assets (css, images, etc.):<\/p>\n<pre class=\"gutter: false;brush:bash\">$ mkdir -p static\/css<\/pre>\n<p>Now create the file\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">static\/css\/style.css<\/code>\u00a0and include the following:<\/p>\n<pre class=\"gutter: false;brush:bash\">h1 {\r\n  margin-top: 2em;\r\n}\r\n\r\n.jumbotron {\r\n  margin-top: 2em;\r\n}<\/pre>\n<p>Now, if you want to run this simple website, you can do so by installing the required dependencies, then starting up your Node server on the command line:<\/p>\n<pre class=\"gutter: false;brush:bash\">$ npm install express pug     # install dependencies\r\n$ node server.js              # run the server<\/pre>\n<p>Once the server is running, you can view the site by visiting\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\"><a class=\"vglnk\" href=\"http:\/\/localhost:3000\/\" rel=\"nofollow\">http:\/\/localhost:3000<\/a><\/code>\u00a0in your browser.<\/p>\n<p>Remember how I said this would be a simple website? I wasn\u2019t lying! Here\u2019s what your new website homepage will look like:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/6.png\"><img decoding=\"async\" class=\"aligncenter wp-image-19261\" style=\"border: none;\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/6.png\" alt=\"\" width=\"860\" height=\"469\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/6.png 1440w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/6-300x164.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/6-768x419.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/6-1024x559.png 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>By now, you should have a working website with no authentication. So let\u2019s take it one step further in the next section and add OIDC.<\/p>\n<h3 id=\"add-openid-connect-to-your-website\">Add OpenID Connect to Your Website<\/h3>\n<p>To get started, you\u2019ll need to install two new Node.js libraries:<\/p>\n<p><a href=\"https:\/\/github.com\/expressjs\/session\">express-session<\/a>, which will manage user sessions for your website, and\u00a0<a href=\"https:\/\/github.com\/okta\/okta-oidc-js\">oidc-middleware<\/a>, which will handle all of the OIDC implementation details for your website<\/p>\n<p>To install these libraries, run the following command:<\/p>\n<pre class=\"gutter: false;brush:bash\">$ npm install express-session @okta\/oidc-middleware<\/pre>\n<p>Next, you\u2019ll need to import these libraries in your\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">server.js<\/code>\u00a0from before:<\/p>\n<pre class=\"gutter: false;brush:php\">const express = require(\"express\");\r\nconst session = require(\"express-session\");\r\nconst ExpressOIDC = require(\"@okta\/oidc-middleware\").ExpressOIDC;<\/pre>\n<p>Now that the libraries are imported properly, you can initialize the session middleware and the OIDC middleware:<\/p>\n<pre class=\"gutter: false;brush:php\">\/\/ App middleware\r\napp.use(\"\/static\", express.static(\"static\"));\r\n\r\napp.use(session({\r\n  cookie: { httpOnly: true },\r\n  secret: \"long random string\"\r\n}));\r\n\r\nlet oidc = new ExpressOIDC({\r\n  issuer: \"https:\/\/dev-111464.oktapreview.com\/oauth2\/default\",\r\n  client_id: \"your-client-id-here\",\r\n  client_secret: \"your-client-secret-here\",\r\n  redirect_uri: \"http:\/\/localhost:3000\/authorization-code\/callback\",\r\n  routes: {\r\n    callback: { defaultRedirect: \"\/dashboard\" }\r\n  },\r\n  scope: 'openid profile'\r\n});<\/pre>\n<p>The session middleware contains a number\u00a0<a href=\"https:\/\/github.com\/expressjs\/session\">of options<\/a>, but the only ones we\u2019ll need for now are the following two:<\/p>\n<ul>\n<li><code class=\"highlighter-rouge\" style=\"font-size: 13px;\">cookie.httponly<\/code>: this option tells the browser that JavaScript code should not be allowed to access the session data. JavaScript on clients is a dangerous thing, ensuring your cookies that contain identity information are safe is always of top importance.<\/li>\n<li><code class=\"highlighter-rouge\" style=\"font-size: 13px;\">secret<\/code>: this option should be a long random string that you create. It should be the same across all your webservers, but never shared publicly or stored in a public place. This value is used to ensure your user\u2019s identity information is protected cryptographically inside of cookies.<\/li>\n<\/ul>\n<p>The OIDC middleware also contains a number\u00a0<a href=\"https:\/\/www.npmjs.com\/package\/@okta\/oidc-middleware#new-expressoidcconfig\">of options<\/a>. I\u2019ll walk you through them briefly:<\/p>\n<ul>\n<li><code class=\"highlighter-rouge\" style=\"font-size: 13px;\">issuer<\/code>: this should be your Org URL value (that you wrote down earlier) with\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">\/oauth2\/default<\/code>\u00a0appended. This is the OAuth2 endpoint that\u2019s used for handling authorization.<\/li>\n<li><code class=\"highlighter-rouge\" style=\"font-size: 13px;\">client_id\/client_secret<\/code>: these values are what you wrote down earlier after creating your Okta Application. They can be found in your Application settings in Okta.<\/li>\n<li><code class=\"highlighter-rouge\" style=\"font-size: 13px;\">redirect_uri<\/code>: this setting tells Okta where to redirect the user after they\u2019ve signed in. This value should stay the same as it is listed above, as this library will handle that route for you automatically.<\/li>\n<li><code class=\"highlighter-rouge\" style=\"font-size: 13px;\">routes.callback.default_redirect<\/code>: this option tells Okta where to redirect a user once they\u2019ve been signed into your website. In this case, you\u2019ll want to redirect them to the dashboard page.<\/li>\n<li><code class=\"highlighter-rouge\" style=\"font-size: 13px;\">scope<\/code>: the OpenID Connect protocol has a lot of standard scopes that determine what data about your user is returned to you once the user has been signed in. The values here provide basic user information for your website. To view a complete list of available scopes, check out\u00a0<a href=\"https:\/\/developer.okta.com\/standards\/OIDC\/index.html#scope-dependent-claims-not-always-returned\">this page<\/a>.<\/li>\n<\/ul>\n<p>Now that you\u2019ve configured OIDC for your website, it\u2019s time to hook up the routes:<\/p>\n<pre class=\"gutter: false;brush:php\">\/\/ App routes\r\napp.use(oidc.router);\r\n\r\napp.get(\"\/\", (req, res) =&gt; {\r\n  res.render(\"index\");\r\n});\r\n\r\napp.get(\"\/dashboard\", oidc.ensureAuthenticated(), (req, res) =&gt; {\r\n  console.log(req.userinfo);\r\n  res.render(\"dashboard\", { user: req.userinfo });\r\n});\r\n\r\napp.get(\"\/logout\", (req, res) =&gt; {\r\n  req.logout();\r\n  res.redirect(\"\/\");\r\n});<\/pre>\n<p>The first thing that\u2019s happening above is that you\u2019re using the built-in OIDC routes that ship with the oidc-middleware library. This library provides routes to handle authenticating the user properly (behind the scenes), and a number of other things. I\u2019ll show you how these work soon.<\/p>\n<p>You\u2019ll also notice that your dashboard route is now using a new Node.js middleware:\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">oidc.ensureAuthenticated()<\/code>. This middleware will do the following:<\/p>\n<ul>\n<li>If a user tries to visit\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">\/dashboard<\/code>\u00a0and is not logged in, they will be redirected to Okta to log in, before being allowed to visit the page<\/li>\n<li>If a user tries to visit\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">\/dashboard<\/code>\u00a0and they\u00a0<em>are<\/em>\u00a0logged in, they will be allowed to view the page with no problems<\/li>\n<\/ul>\n<p>You\u2019ll also notice that inside the dashboard route, you\u2019re now able to access the logged-in user\u2019s personal information via\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">req.userinfo<\/code>. The oidc-middleware library makes this object available to you whenever a user is logged in. You\u2019ll notice that that this object shows the following information:<\/p>\n<pre class=\"gutter: false;brush:bash\">{ sub: '00uc5nynm5RZivEun0h7',\r\n  name: 'Randall Degges',\r\n  locale: 'en-US',\r\n  preferred_username: 'r@rdegges.com',\r\n  given_name: 'Randall',\r\n  family_name: 'Degges',\r\n  zoneinfo: 'America\/Los_Angeles',\r\n  updated_at: 1507772025 }<\/pre>\n<p>The data that\u2019s returned about each logged-in user can be modified by including more (or fewer) scopes (as mentioned previously).<\/p>\n<p>In the code above, you\u2019ll also notice that there is a real logout implementation. The oidc-middleware library includes a new method:\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">req.logout()<\/code>, which wipes all session data and logs the user out of your application.<\/p>\n<h3 id=\"modify-the-server-start\">Modify the Server Start<\/h3>\n<p>Now that you\u2019ve got your code in place, there\u2019s only one tiny piece of code left to change: the code that starts your web server.<\/p>\n<p>Normally when your Node application starts running, via the\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">app.listen()<\/code>\u00a0method, the web site is immediately online. Now that you\u2019re using OIDC, however, you don\u2019t actually want that behavior.<\/p>\n<p>In order to set up the OIDC rules and policies, the oidc-middleware library performs its setup routines asynchronously. If your site was to immediately go online, it could cause errors when users try to view protected pages, etc.<\/p>\n<p>To get around this, you\u2019ll want to modify your server start code like so:<\/p>\n<pre class=\"gutter: false;brush:bash\">oidc.on(\"ready\", () =&gt; {\r\n  app.listen(3000);\r\n});\r\n\r\noidc.on(\"error\", err =&gt; {\r\n  console.error(err);\r\n});<\/pre>\n<p>By listening for the events that the oidc-middleware library provides, you can safely start your Node server as soon as the OIDC setup has finished, thereby solving any timing problems you might have run into otherwise.<\/p>\n<h2 id=\"test-it-out\">Test It Out<\/h2>\n<p>Now that your application has been built, why not try it out? If you visit\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\"><a class=\"vglnk\" href=\"http:\/\/localhost:3000\/\" rel=\"nofollow\">http:\/\/localhost:3000<\/a><\/code>\u00a0and click through the prompts, you\u2019ll see how everything fits together:<\/p>\n<p>Once you click login, you\u2019ll be redirected to\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">\/login<\/code>\u00a0The oidc-middleware will intercept that\u00a0<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">\/login<\/code>\u00a0request, and redirect the user to Okta\u2019s hosted sign-in page where they\u2019ll be prompted for their email address and password The user will then enter their credentials, and log in They will then be redirected back to your local website, where the oidc-middleware library will again intercept the request, create a session for the user, and log them in Finally, they will be redirected to the dashboard page (<code class=\"highlighter-rouge\" style=\"font-size: 13px;\">\/dashboard<\/code>), where your route code will run and echo their basic information back to them<\/p>\n<p>Here\u2019s what each of the pages looks like in the flow:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/7.png\"><img decoding=\"async\" class=\"aligncenter wp-image-19262\" style=\"border: none;\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/7.png\" alt=\"\" width=\"860\" height=\"469\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/7.png 1440w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/7-300x164.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/7-768x419.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/7-1024x559.png 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>Then, once you click \u201clogin\u201d, you\u2019ll be taken to the login page:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/8.png\"><img decoding=\"async\" class=\"aligncenter wp-image-19263\" style=\"border: none;\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/8.png\" alt=\"\" width=\"860\" height=\"469\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/8.png 1440w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/8-300x164.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/8-768x419.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/8-1024x559.png 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>Finally, once you\u2019ve logged in, you\u2019ll be taken to the dashboard page where you can view your user information:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/9.png\"><img decoding=\"async\" class=\"aligncenter wp-image-19264\" style=\"border: none;\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/9.png\" alt=\"\" width=\"860\" height=\"469\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/9.png 1440w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/9-300x164.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/9-768x419.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/9-1024x559.png 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<h2 id=\"resources\">Resources<\/h2>\n<p>Now that you\u2019ve built your first Node.js site using OIDC to handle authentication using our new\u00a0<a href=\"https:\/\/github.com\/okta\/okta-oidc-js\">oidc-middleware library<\/a>, you might want to learn more about OIDC.<\/p>\n<p>One of my good friends and co-workers\u00a0<a href=\"https:\/\/twitter.com\/afitnerd\">Micah Silverman<\/a>\u00a0recently published a three part primer to OIDC which I strongly recommend you read if you\u2019re interested in learning more about OIDC. You can\u00a0<a href=\"https:\/\/developer.okta.com\/blog\/2017\/07\/25\/oidc-primer-part-1\">check it out here<\/a>.<\/p>\n<p>You can also\u00a0<a href=\"https:\/\/twitter.com\/rdegges\">follow myself<\/a>\u00a0and\u00a0<a href=\"https:\/\/twitter.com\/oktadev\">Okta<\/a>\u00a0on Twitter to see more of what I\u2019m working on, and ask any auth-related questions you might have.<\/p>\n<p><span style=\"font-size: 20px;\"><b>\u201cI love writing authentication and authorization code.\u201d ~ No Web Developer Ever.<\/b> Tired of building the same login screens over and over? <a href=\"https:\/\/developer.okta.com\/signup\/?utm_campaign=Syndication%3EGlobal%3Eopenid-connect-build-simple-node-website-FY18Q4&amp;utm_medium=post&amp;utm_source=web-code-geeks-all-developer\">Try the Okta API for hosted authentication, authorization, and multi-factor auth.<\/a> <\/span><\/p>\n<p><a href=\"https:\/\/developer.okta.com\/blog\/2017\/10\/19\/use-openid-connect-to-build-a-simple-node-website\">Use OpenID Connect to Build a Simple Node.js Website<\/a>\u00a0was originally published on the Okta developer blog on October 19, 2017.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u201cI love writing authentication and authorization code.\u201d ~ No Web Developer Ever. Tired of building the same login screens over and over? Try the Okta API for hosted authentication, authorization, and multi-factor auth. User authentication in Node can be confusing. It\u2019s confusing for lots of people, including really talented Node developers, so you\u2019re not alone. &hellip;<\/p>\n","protected":false},"author":1264,"featured_media":924,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[499,500,387],"class_list":["post-19255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js","tag-okta","tag-openid","tag-security"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Secure Your Node.js Website with OpenID Connect - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"\u201cI love writing authentication and authorization code.\u201d ~ No Web Developer Ever. Tired of building the same login screens over and over? Try the Okta API\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Secure Your Node.js Website with OpenID Connect - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"\u201cI love writing authentication and authorization code.\u201d ~ No Web Developer Ever. Tired of building the same login screens over and over? Try the Okta API\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-27T07:00:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-09T09:58:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Randall Degges\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Randall Degges\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/\"},\"author\":{\"name\":\"Randall Degges\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c8e794de4537292b783d6f151f534fba\"},\"headline\":\"Secure Your Node.js Website with OpenID Connect\",\"datePublished\":\"2017-11-27T07:00:16+00:00\",\"dateModified\":\"2017-12-09T09:58:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/\"},\"wordCount\":2294,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"keywords\":[\"Okta\",\"OpenID\",\"Security\"],\"articleSection\":[\"Node.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/\",\"name\":\"Secure Your Node.js Website with OpenID Connect - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"datePublished\":\"2017-11-27T07:00:16+00:00\",\"dateModified\":\"2017-12-09T09:58:23+00:00\",\"description\":\"\u201cI love writing authentication and authorization code.\u201d ~ No Web Developer Ever. Tired of building the same login screens over and over? Try the Okta API\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Node.js\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Secure Your Node.js Website with OpenID Connect\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c8e794de4537292b783d6f151f534fba\",\"name\":\"Randall Degges\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/aee899105ee2856c68bbb4f0c52e5defc6945c88631ee796979d69d6b148578b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/aee899105ee2856c68bbb4f0c52e5defc6945c88631ee796979d69d6b148578b?s=96&d=mm&r=g\",\"caption\":\"Randall Degges\"},\"sameAs\":[\"https:\/\/developer.okta.com\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/randall-degges\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Secure Your Node.js Website with OpenID Connect - Web Code Geeks - 2026","description":"\u201cI love writing authentication and authorization code.\u201d ~ No Web Developer Ever. Tired of building the same login screens over and over? Try the Okta API","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/","og_locale":"en_US","og_type":"article","og_title":"Secure Your Node.js Website with OpenID Connect - Web Code Geeks - 2026","og_description":"\u201cI love writing authentication and authorization code.\u201d ~ No Web Developer Ever. Tired of building the same login screens over and over? Try the Okta API","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2017-11-27T07:00:16+00:00","article_modified_time":"2017-12-09T09:58:23+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","type":"image\/jpeg"}],"author":"Randall Degges","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Randall Degges","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/"},"author":{"name":"Randall Degges","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c8e794de4537292b783d6f151f534fba"},"headline":"Secure Your Node.js Website with OpenID Connect","datePublished":"2017-11-27T07:00:16+00:00","dateModified":"2017-12-09T09:58:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/"},"wordCount":2294,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","keywords":["Okta","OpenID","Security"],"articleSection":["Node.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/","name":"Secure Your Node.js Website with OpenID Connect - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","datePublished":"2017-11-27T07:00:16+00:00","dateModified":"2017-12-09T09:58:23+00:00","description":"\u201cI love writing authentication and authorization code.\u201d ~ No Web Developer Ever. Tired of building the same login screens over and over? Try the Okta API","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/secure-node-js-website-openid-connect\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"Node.js","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/"},{"@type":"ListItem","position":4,"name":"Secure Your Node.js Website with OpenID Connect"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c8e794de4537292b783d6f151f534fba","name":"Randall Degges","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/aee899105ee2856c68bbb4f0c52e5defc6945c88631ee796979d69d6b148578b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/aee899105ee2856c68bbb4f0c52e5defc6945c88631ee796979d69d6b148578b?s=96&d=mm&r=g","caption":"Randall Degges"},"sameAs":["https:\/\/developer.okta.com"],"url":"https:\/\/www.webcodegeeks.com\/author\/randall-degges\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/19255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/1264"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=19255"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/19255\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/924"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=19255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=19255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=19255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}