Skip to content

Express 4 samples. Will publish an artifact that can be consumed by end-to-end sample repos

License

Notifications You must be signed in to change notification settings

okta/samples-nodejs-express-4

This branch is 1 commit ahead of, 6 commits behind master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

df3c785 · Nov 11, 2023
Feb 17, 2021
Mar 1, 2021
Mar 1, 2021
Dec 19, 2019
Aug 29, 2023
Jun 12, 2019
Aug 29, 2023
Jan 6, 2018
Jun 12, 2019
May 26, 2022
May 13, 2019
Nov 29, 2016
Jan 13, 2020
Oct 24, 2019
Nov 11, 2023
Nov 11, 2023

Repository files navigation

Express Sample Applications for Okta

This repository contains several sample applications that show you how to integrate various Okta use-cases into your Node.js application that uses the Express framework.

Configuration

All of the samples share a single configuration file, config.js. The config uses environment variables which can be either exported in the shell or stored in a file named testenv in this directory. See dotenv for more details on this file format. It may look something like:

ISSUER=https://yourOktaDomain.com/oauth2/default

# Web app
CLIENT_ID=123XX
CLIENT_SECRET=456XX

# SPA app
SPA_CLIENT_ID=123YY

Please find the sample that fits your use-case from the table below.

Sample Description Use-Case
Okta-Hosted Login An application server that uses the hosted login page on your Okta org, then creates a cookie session for the user in the Express application. Traditional web applications with server-side rendered pages.
Custom Login Page An application server that uses the Okta Sign-In Widget on a custom login page within the application, then creates a cookie session for the user in the Express application. Traditional web applications with server-side rendered pages.
Resource Server This is a sample API resource server that shows you how to authenticate requests with access tokens that have been issued by Okta. Single-Page applications.

Running the tests

Before running the tests you will need to gather values for ALL required environment variables. You can export these variables in the shell or store them in a file named testenv in the current directory.

You will need two Okta applications, one Web app and one SPA app. Save the clientId for the Web app as CLIENT_ID and the clientId for the SPA app as SPA_CLIENT_ID

The Web app needs a couple of settings in the Developer console: Add a Login redirect URI: http://localhost:8080/authorization-code/callback Add a Logout redirect URI: http://localhost:8080

You will also need credentials for a test user.

ISSUER=https://yourOktaDomain.com/oauth2/default
CLIENT_ID=123xxxxx123
CLIENT_SECRET=1234XXX
SPA_CLIENT_ID=123yyyy123
USERNAME=testuser
PASSWORD=testpass

With all variables set, run npm test