Registry / security / nest-oidc-provider

nest-oidc-provider

JSON →
library2.1.0jsnpmunverified

NestJS module wrapping oidc-provider v8+, enabling ESM-only OIDC provider integration in NestJS applications. Version 2.1.0 requires NestJS >=9, oidc-provider >=8.5.1, and Node >=18. Provides decorators (@InjectOidcModule, @InjectOidcProvider), OidcModule.forRoot(), and automatic ESM detection to work around NestJS's CJS-only runtime. Key differentiator: handles the oidc-provider v8 ESM transition transparently, re-exports all types, and supports custom factory functions, proxy trust, and dynamic host routing. Ships TypeScript definitions.

npm install nest-oidc-provider
INSTALL
IMPORT
SIG · NEST-OIDC-PROVIDER
N
nest-oidc-provider
securityjavascriptv2.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OidcModule
import { OidcModule } from 'nest-oidc-provider'
const OidcModule = require('nest-oidc-provider').OidcModule
The module class; use forRoot() static method in imports array.
InjectOidcProvider
import { InjectOidcProvider } from 'nest-oidc-provider'
import { InjectOIDCProvider } from 'nest-oidc-provider'
Decorator to inject the running Provider instance. Note exact casing: 'InjectOidcProvider' (not 'OIDC').
InjectOidcModule
import { InjectOidcModule } from 'nest-oidc-provider'
import { InjectOIDCModule } from 'nest-oidc-provider'
Decorator to inject the oidc-provider module (the default export from oidc-provider).
OidcModuleOptions
import { OidcModuleOptions } from 'nest-oidc-provider'
import OidcModuleOptions from 'nest-oidc-provider'
TypeScript interface for options passed to forRoot(). Use as type only.

Basic NestJS module setup with OIDC provider, a client, PKCE disabled, and cookie keys.

import { Module } from '@nestjs/common'; import { OidcModule } from 'nest-oidc-provider'; @Module({ imports: [ OidcModule.forRoot({ issuer: 'http://localhost:3000', path: '/oidc', oidc: { clients: [{ client_id: 'my-client', client_secret: 'secret', grant_types: ['authorization_code'], redirect_uris: ['http://localhost:4000/cb'], }], pkce: { required: () => false }, cookies: { keys: ['some-secret-key-123'], }, }, }), ], }) export class AppModule {}
Debug
Known issues
breakingoidc-provider v8 is ESM-only — NestJS (as of v10) does not support ESM natively. This library uses dynamic imports internally, but you must NOT directly import from 'oidc-provider' in NestJS code (CJS context). Always use dependency injection decorators.
fix
Import everything from 'nest-oidc-provider' and use @InjectOidcModule() / @InjectOidcProvider() to access provider internals. If you need types, use the re-exports from this package.
affects: >=2.0.0
gotchaThe @InjectOidcProvider() decorator uses string-based injection token 'OIDC_PROVIDER' and does not have type safety for the provider instance. If you need Provider methods, you may need to cast or use the Provider type from oidc-provider.
fix
Use type assertion: (provider as import('oidc-provider').Provider).someMethod()
affects: >=2.0.0
deprecatedOidcModule.forRootAsync() is deprecated in favor of using forRoot() with a factory function inside the options.
fix
Use forRoot({ ... }) with the factory option to customize provider instantiation.
affects: >=2.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module oidc-provider from ... not supported.
Direct require() or import of 'oidc-provider' in a CJS context (NestJS default).
fix
Remove any import from 'oidc-provider' in your NestJS code. Use imports from 'nest-oidc-provider' instead.
Cannot find module 'oidc-provider' or its corresponding type declarations.
'oidc-provider' not installed as a dependency. It is a peer dependency and must be installed separately.
fix
npm install oidc-provider --save
The OIDC provider instance is undefined when using @InjectOidcProvider() in a provider constructor.
The module containing OidcModule.forRoot() may not be imported, or the provider is not registered before injection.
fix
Ensure the OidcModule is imported in the appropriate module (usually AppModule). Check that @InjectOidcProvider() is used in the same module context.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
@nestjs/commonrequiredPeer dependency for NestJS module system
@nestjs/corerequiredPeer dependency for NestJS module system
oidc-providerrequiredPeer dependency for the actual OIDC provider implementation
reflect-metadatarequiredRequired by NestJS for dependency injection
Agent activity
8 hits · last 30 days
node
8
Resources
nest-oidc-provider — npm install nest-oidc-provider · libregistry