Menu

1 / 2

Part II: Persisting OpenID Server Data on MongoDB with Node.js

DEV Community·Ebrahim Hoseiny Fadae·7 months ago
#8PU8TQDv
#comment#node#openid#koa#mongodb
Reading 0:00
15s threshold

Introduction

In this article, we'll explore how to integrate MongoDB with an OIDC ( OpenID Connect 1.0 ) authentication server. We'll be using the panava/node-oidc-provider library for implementing the OIDC server and the Mongoose for connecting to MongoDB.

Let's start

Assuming you have followed the previous articles, you only need to add the necessary database dependencies.

$ yarn add [email protected] -T

Enter fullscreen mode

Exit fullscreen mode

Connect to MongoDB

For connecting to the MongoDB instance we only need to call connect from the mongoose library.

./oidc/src/db/mongodb/connection.ts

import mongoose from " mongoose " ;

export default async () => { const URI = process . env . MONGODB_URI ?? "" ; try { return await mongoose . connect ( URI , {}); } catch ( error ) { console . error ( error ); } };

Enter fullscreen mode

Exit fullscreen mode

Add Base model

Now that we have our database connected, we need to design our models to store the data.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.