{"id":19577153,"url":"https://github.com/adrianbrs/nest-oidc-provider","last_synced_at":"2025-10-09T01:11:44.279Z","repository":{"id":42165684,"uuid":"452898899","full_name":"adrianbrs/nest-oidc-provider","owner":"adrianbrs","description":"oidc-provider module for Nest framework (node.js)","archived":false,"fork":false,"pushed_at":"2025-09-26T06:21:24.000Z","size":1463,"stargazers_count":72,"open_issues_count":0,"forks_count":19,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-09T01:06:34.888Z","etag":null,"topics":["nest","nestjs","oauth2","openid","openid-connect","openid-provider","provider","server"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adrianbrs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["adrianbrs"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2022-01-28T01:12:58.000Z","updated_at":"2025-09-30T17:23:31.000Z","dependencies_parsed_at":"2024-06-21T17:37:50.054Z","dependency_job_id":"120a6117-5671-4fe3-ab3a-4c530aab4d94","html_url":"https://github.com/adrianbrs/nest-oidc-provider","commit_stats":{"total_commits":64,"total_committers":4,"mean_commits":16.0,"dds":0.25,"last_synced_commit":"50bcba0f204d12c1d75146e7f7ffc3b50875a1ff"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/adrianbrs/nest-oidc-provider","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianbrs%2Fnest-oidc-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianbrs%2Fnest-oidc-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianbrs%2Fnest-oidc-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianbrs%2Fnest-oidc-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adrianbrs","download_url":"https://codeload.github.com/adrianbrs/nest-oidc-provider/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianbrs%2Fnest-oidc-provider/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000722,"owners_count":26082894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nest","nestjs","oauth2","openid","openid-connect","openid-provider","provider","server"],"created_at":"2024-11-11T07:04:45.698Z","updated_at":"2025-10-09T01:11:44.243Z","avatar_url":"https://github.com/adrianbrs.png","language":"TypeScript","funding_links":["https://github.com/sponsors/adrianbrs"],"categories":[],"sub_categories":[],"readme":"# nest-oidc-provider\n\n[![NPM Version](https://img.shields.io/npm/v/nest-oidc-provider.svg)](https://www.npmjs.com/package/nest-oidc-provider)\n[![npm](https://img.shields.io/npm/dw/nest-oidc-provider)](https://www.npmjs.com/package/nest-oidc-provider)\n[![NPM License](https://img.shields.io/npm/l/nest-oidc-provider)](https://github.com/adrianbrs/nest-oidc-provider/blob/main/LICENSE)\n[![Coverage Status](https://coveralls.io/repos/github/adrianbrs/nest-oidc-provider/badge.svg?branch=main)](https://coveralls.io/github/adrianbrs/nest-oidc-provider?branch=main)\n[![Continuous Integration](https://github.com/adrianbrs/nest-oidc-provider/actions/workflows/test.yml/badge.svg)](https://github.com/adrianbrs/nest-oidc-provider/actions/workflows/test.yml)\n\n## Description\n\n[oidc-provider](https://github.com/panva/node-oidc-provider) module for [Nest](https://github.com/nestjs/nest) framework (node.js)\n\n## Installation\n\n```bash\n$ npm i --save nest-oidc-provider oidc-provider\n```\n\nOR\n\n```bash\n$ yarn add nest-oidc-provider oidc-provider\n```\n\nOR\n\n```bash\n$ pnpm add nest-oidc-provider oidc-provider\n```\n\n## Setup\n\n\u003e ⚠️ Version 8 of `oidc-provider` [is now ESM-only](\u003chttps://github.com/panva/node-oidc-provider/releases/tag/v8.0.0#:~:text=tokens%20(cb67083)-,oidc%2Dprovider%20is%20now%20an%20ESM%2Donly%20module,-(3c5ebe1)\u003e), which is not yet supported by NestJS natively ([nest#7021](https://github.com/nestjs/nest/issues/7021), [nest#8736](https://github.com/nestjs/nest/pull/8736)). This library enables the use of the ESM-only version of `oidc-provider` for Node.js \u003c= 20.17.x via dynamic imports. To avoid errors like [ERR_REQUIRE_ESM], all interfaces should be imported from this package, and the module should be accessed through dependency injection. Use `@InjectOidcModule()` to inject the `oidc-provider` module and `@InjectOidcProvider()` for the running instance. **You must not import anything directly from** `oidc-provider`, unless you're using Node.js \u003e= 20.17.x with the experimental `--experimental-require-module` flag ([#54447](https://github.com/nodejs/node/pull/54447))!\n\n### TypeScript\n\nYou need to install the `oidc-provider` @types package if you want to use the re-exported types from this library.\n\n```bash\nnpm install @types/oidc-provider --save-dev\n```\n\n### Basic configuration\n\n```ts\n@Module({\n  imports: [\n    OidcModule.forRoot({\n      issuer: 'http://localhost:3000',\n      path: '/oidc',\n      oidc: ... // oidc-provider configuration\n    })\n  ],\n})\nexport class AppModule {}\n```\n\n### Custom factory function\n\nYou can pass a `factory` function to customize the provider instantiation.\n\n```ts\n@Module({\n  imports: [\n    OidcModule.forRoot({\n      issuer: 'http://localhost:3000',\n      path: '/oidc',\n      factory: ({ issuer, config, module }) =\u003e {\n        // `module` is the import from `oidc-provider`\n        const provider = new module.Provider(issuer, config);\n        provider.on('server_error', (ctx, err) =\u003e {...})\n        return provider;\n      },\n      oidc: ... // oidc-provider configuration\n    })\n  ],\n})\nexport class AppModule {}\n```\n\n### Trusting TLS offloading proxies\n\nYou can set the `proxy` option to `true` to trust TLS offloading proxies.\\\nFor more info visit the `oidc-provider` documentation: [Trusting TLS offloading proxies](https://github.com/panva/node-oidc-provider/blob/v7.12.0/docs/README.md#trusting-tls-offloading-proxies)\n\n```ts\n@Module({\n  imports: [\n    OidcModule.forRoot({\n      issuer: 'http://localhost:3000',\n      path: '/oidc',\n      proxy: true, // \u003c- trust TLS offloading proxies\n      oidc: {...}\n    })\n  ],\n})\nexport class AppModule {}\n```\n\n### Dynamic host routing\n\nYou can set the `host` option to require the HTTP host of incoming requests to match some specific value before they are processed by the [`oidc-provider`](https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#basic-configuration-example) callback.\n\nFor more info visit the NestJS documentation: [Sub-domain routing](https://docs.nestjs.com/controllers#sub-domain-routing).\n\n```ts\n@Module({\n  imports: [\n    OidcModule.forRoot({\n      issuer: 'https://oidc.example.com',\n      path: '/oidc',\n      host: 'oidc.example.com', // \u003c- Use a specific host/subdomain\n      oidc: {...}\n    })\n  ],\n})\nexport class AppModule {}\n```\n\n### Async configuration\n\n#### `useFactory`\n\n```ts\n@Module({\n  imports: [\n    OidcModule.forRootAsync({\n      imports: [ConfigModule],\n      useFactory: async (configService: ConfigService) =\u003e ({\n        issuer: configService.get\u003cstring\u003e('ISSUER'),\n        path: configService.get\u003cstring\u003e('OIDC_PATH'),\n        oidc: ... // oidc-provider configuration\n      }),\n      inject: [ConfigService],\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n#### `useClass`\n\n```ts\n@Module({\n  imports: [\n    OidcModule.forRootAsync({\n      useClass: OidcConfigService,\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\nNote that in this example, the `OidcConfigService` has to implement the `OidcModuleOptionsFactory` interface, as shown below.\n\n```ts\nimport type { OidcModuleOptionsFactory } from 'nest-oidc-provider';\n\n@Injectable()\nexport class OidcConfigService implements OidcModuleOptionsFactory {\n  constructor(private readonly @InjectConnection() conn: Connection) {}\n\n  createModuleOptions(): OidcModuleOptions {\n    return {\n      issuer: 'http://localhost:3001',\n      path: '/oidc',\n      oidc: ..., // oidc-provider configuration\n    };\n  }\n\n  createAdapterFactory?(): AdapterFactory {\n    return (modelName: string) =\u003e new MyAdapter(modelName, this.conn);\n  }\n}\n```\n\nYou can omit the `Adapter` option of oidc-provider configuration if you implement the `createAdapterFactory` method.\n\n#### `useExisting`\n\n```ts\n@Module({\n  imports: [\n    OidcModule.forRootAsync({\n      imports: [OidcConfigModule],\n      useExisting: OidcConfigService,\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n## Custom injection decorators\n\nTo be able to access the exports of the `oidc-provider` module or the running instance, you need to use decorators or injection tokens:\n\n```ts\nimport {\n  InjectOidcModule,\n  InjectOidcProvider,\n  type Provider,\n  type ProviderModule,\n} from 'nest-oidc-provider';\n\n@Controller('/some-controller')\nexport class SomeController {\n  constructor(\n    /** Returns exports from the `oidc-provider` module */\n    @InjectOidcModule() oidc: ProviderModule,\n    /** Returns the running `oidc-provider` instance */\n    @InjectOidcProvider() provider: Provider,\n  ) {}\n}\n```\n\nOR\n\n```ts\nimport {\n  OIDC_PROVIDER,\n  OIDC_PROVIDER_MODULE,\n  type Provider,\n  type ProviderModule,\n} from 'nest-oidc-provider';\n\nasync function bootstrap() {\n  const app = await NestFactory.create\u003cNestExpressApplication\u003e(AppModule);\n\n  const { Provider, errors, interactionPolicy } =\n    app.get\u003cProviderModule\u003e(OIDC_PROVIDER_MODULE);\n  const provider = app.get\u003cProvider\u003e(OIDC_PROVIDER);\n\n  await app.listen(3000);\n}\n```\n\n## Custom param decorators\n\n### `@OidcInteraction()`\n\nReturns an instance of `InteractionHelper` class.\n\n```ts\nimport { OidcInteraction, type InteractionHelper } from 'nest-oidc-provider';\n\n@Get(':uid')\n@Render('login')\nasync login(\n  @OidcInteraction() interaction: InteractionHelper\n) {\n  const { prompt, params, uid } = await interaction.details();\n\n  const client = await this.provider.Client.find(params.client_id as string);\n\n  return { prompt, client, params, uid, ...};\n}\n```\n\nThe `InteractionHelper` class is just a helper that omits the `req` and `res` parameters from the existing interaction methods in `oidc-provider`.\n\n```ts\ninterface InteractionHelper {\n  details(): Promise\u003cInteractionDetails\u003e;\n\n  finished(\n    result: InteractionResults,\n    options?: { mergeWithLastSubmission?: boolean },\n  ): Promise\u003cvoid\u003e;\n\n  result(\n    result: InteractionResults,\n    options?: { mergeWithLastSubmission?: boolean },\n  ): Promise\u003cstring\u003e;\n}\n```\n\n### `@OidcContext()`\n\nReturns an instance of `KoaContextWithOIDC`.\n\n```ts\nimport { OidcContext, type KoaContextWithOIDC } from 'nest-oidc-provider';\n\n@Get()\nasync index(@OidcContext() ctx: KoaContextWithOIDC) {\n  const { oidc: { provider } } = ctx;\n  const session = await provider.Session.get(ctx);\n  //...\n}\n```\n\n### `@OidcSession()`\n\nReturns the user `Session` from the current context, equivalent to retrieving the session from `KoaContextWithOIDC`.\n\n```ts\nimport { OidcSession, type Session } from 'nest-oidc-provider';\n\n@Get()\nasync index(@OidcSession() session: Session) {\n  //...\n}\n```\n\n## Examples\n\nA complete example can be found in the [example](example) directory.\n\n## Contributing\n\nYou are welcome to contribute to this project, just open a PR.\n\n## CHANGELOG\n\nSee [CHANGELOG](CHANGELOG.md) for more information.\n\n## License\n\nThis project is [MIT licensed](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianbrs%2Fnest-oidc-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrianbrs%2Fnest-oidc-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianbrs%2Fnest-oidc-provider/lists"}