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.…