https://github.com/oktadev/okta-nodejs-login-example
Node.js Login Example
https://github.com/oktadev/okta-nodejs-login-example
authentication express login node nodejs
Last synced: 7 months ago
JSON representation
Node.js Login Example
- Host: GitHub
- URL: https://github.com/oktadev/okta-nodejs-login-example
- Owner: oktadev
- License: apache-2.0
- Created: 2020-05-20T16:31:29.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-21T11:11:13.000Z (almost 5 years ago)
- Last Synced: 2025-04-11T15:14:47.229Z (10 months ago)
- Topics: authentication, express, login, node, nodejs
- Language: JavaScript
- Homepage: https://developer.okta.com/blog/2020/06/16/nodejs-login
- Size: 249 KB
- Stars: 6
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node.js + Express Login Example
This example shows how to add Login to a Node.js application. Please read [Node.js Login with Express and OIDC](https://developer.okta.com/blog/2020/06/16/nodejs-login) to see how it was created.
**Prerequisites:**
* [Node 12](https://nodejs.org/)+
> [Okta](https://developer.okta.com/) has Authentication and User Management APIs that reduce development time with instant-on, scalable user infrastructure. Okta's intuitive API and expert support make it easy for developers to authenticate, manage and secure users and roles in any application.
* [Getting Started](#getting-started)
* [Help](#help)
* [Links](#links)
* [License](#license)
## Getting Started
To install this example application, run the following commands:
```bash
git clone https://github.com/oktadeveloper/okta-nodejs-login-example.git
cd okta-nodejs-login-example
npm install
```
This will get a copy of the project locally.
### Create a Free Okta Developer Account
If you don't have one, [create an Okta Developer account](https://developer.okta.com/signup/). After you've completed the setup process, log in to your account.
Create a new OIDC app by navigating to **Applications** > **Add Application** > select **Web**, and click **Next**. Fill in the following values:
* Name: `Node.js Login`
* Base URI: `http://localhost:3000`
* Login redirect URI: `http://localhost:3000/callback`
* Logout redirect URI: `http://localhost:3000`
Click **Done** to create your app.
Create a `.env` file in your root directory and copy the client ID and secret into it. You can find the value for `` by navigating to **API** > **Authorization Servers**.
```
OIDC_ISSUER=
OIDC_CLIENT_ID=
OIDC_CLIENT_SECRET=
BASE_URL=http://localhost:3000
SESSION_SECRET=todo: make-this-more-secure
```
**NOTE**: Make sure to remove the `<...>` placeholders. Your issuer should look something like: `https://dev-123456.okta.com/oauth2/default`.
### Start the application
Start your application:
```
npm start
```
Log in to `http://localhost:3000` and enjoy your login experience!
## Links
This example uses the following libraries provided by Okta:
* [OktaDev Schematics](https://github.com/oktadeveloper/schematics#readme)
* [OIDC Middleware](https://github.com/okta/okta-oidc-js/tree/master/packages/oidc-middleware)
## Help
Please post any questions as issues in this repo, or visit our [Okta Developer Forums](https://devforum.okta.com/).
## License
Apache 2.0, see [LICENSE](LICENSE).