Skip to content

A simple sample application built using Node and Express that contains user login, registration, and password reset functionality.

License

Notifications You must be signed in to change notification settings

redbmk/okta-node-express-example

 
 

Repository files navigation

Node Express Application with Okta Authentication

This example shows how to create a website in Node and Express that uses Okta for authentication. The application was bootstrapped with Express Generator. You can see it online at https://okta-node-express-example.herokuapp.com.

Please read Simple Node Authentication to see how this application was created.

Getting Started

To install this example application, run the following commands:

git clone [email protected]:oktadeveloper/okta-node-express-example.git
cd okta-node-express-example

This will get a copy of the project install locally. You will need to set up some environment variables before the app will run properly.

To integrate Okta's Identity Platform for user authentication, you'll first need to:

You will need to create an application in Okta:

  • Log in to your Okta account, then navigate to Applications and click the Add Application button
  • Select Web and click Next
  • Give your application a name (e.g. "Simple Node Authentication")
  • Change the Base URI to http://localhost:3000 and the Login redirect URI to http://localhost:3000/authorization-code/callback, then click Done
  • Save your client ID and client secret for later

Your Okta application should have settings similar to the following:

Okta Application Settings

You will also need an API token:

  • Log in to your Okta account, then navigate to API > Tokens and click the Create Token button
  • Enter a name that will help you remember what this is used for (e.g. "registration")
  • Save the provided token value for later
    • This will only be displayed once. If you lose it, you will need to create another API token

Now create a file called .env in the project root and add the following variables, replacing the values with your own from the previous steps.

HOST_URL=http://localhost:3000
ORG_URL=https://dev-123456.oktapreview.com
CLIENT_ID=okta-application-client-id
CLIENT_SECRET=okta-application-client-secret
REGISTRATION_TOKEN=okta-api-token
APP_SECRET=something-random

One way to get a random APP_SECRET is to use the following command line, which will generate a random value and add it to your .env file.

echo "APP_SECRET=`openssl rand -base64 32`" >> .env

Now run the application:

npm install
npm start

If you want to run the application in development mode so that any changes you make automatically restart the web server, instead of npm start use the command npm run dev.

Links

Here are some links that were helpful in the creation of this example:

Help

Please post any questions as comments on the blog post, or visit our Okta Developer Forums. You can also email [email protected] if would like to create a support ticket.

License

Apache 2.0, see LICENSE.

About

A simple sample application built using Node and Express that contains user login, registration, and password reset functionality.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 63.9%
  • HTML 27.1%
  • CSS 9.0%