{"_id":"@c12/nestjs-oauth2-server","name":"@c12/nestjs-oauth2-server","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@c12/nestjs-oauth2-server","version":"0.1.0","description":"A NestJS wrapper for oauth2-server","main":"index.js","types":"index.d.ts","author":{"name":"B'Tunde Aromire"},"keywords":["nestjs oauth2 server","nestjs oauth2","@nestjs/oauth2-server","nest oauth2 server","nestjs","nest"],"directories":{"lib":"lib","test":"test"},"dependencies":{},"devDependencies":{"@commitlint/cli":"11.0.0","@commitlint/config-conventional":"11.0.0","@commitlint/prompt-cli":"11.0.0","@compodoc/compodoc":"1.1.12","@nestjs/common":"7.6.15","@nestjs/core":"7.6.15","@nestjs/platform-express":"7.6.15","@nestjs/testing":"7.6.15","@types/jest":"26.0.23","@types/node":"13.13.52","@types/oauth2-server":"3.0.12","@types/rimraf":"3.0.1","@types/supertest":"2.0.11","@typescript-eslint/eslint-plugin":"4.23.0","@typescript-eslint/parser":"4.23.0","dotenv-cli":"4.0.0","eslint":"7.26.0","eslint-config-prettier":"7.2.0","eslint-plugin-import":"2.22.1","husky":"4.3.8","jest":"26.6.3","lint-staged":"10.5.4","moment":"2.29.1","oauth2-server":"3.1.1","prettier":"2.2.1","reflect-metadata":"0.1.13","release-it":"14.6.2","renovate":"24.119.23","rimraf":"3.0.2","rxjs":"6.6.7","supertest":"6.1.3","ts-jest":"26.5.6","typescript":"4.2.4"},"repository":{"type":"git","url":"git+https://github.com/boyuai/nestjs-oauth2-server.git"},"license":"MIT","bugs":{"url":"https://github.com/boyuai/nestjs-oauth2-server/issues"},"husky":{"hooks":{"commit-msg":"commitlint -E HUSKY_GIT_PARAMS","pre-commit":"lint-staged"}},"lint-staged":{"lib/**/*.ts":["prettier --write"],"test/**/*.ts":["prettier --write"]},"peerDependencies":{"@nestjs/common":"^6.10.0 || ^7.0.0 || ^8.0.10 || ^10.0.0","reflect-metadata":"^0.1.12","rxjs":"^6.0.0 || ^7.2.0"},"homepage":"https://github.com/boyuai/nestjs-oauth2-server#readme","publishConfig":{"access":"public"},"scripts":{"commit":"commit","format":"prettier --write lib/**/*.ts test/**/*.ts","build":"rimraf -rf dist && tsc -p tsconfig.build.json","build:watch":"rimraf -rf dist && tsc -p tsconfig.build.json -w","lint":"eslint lib/**/*.ts --fix","prepublish:npm":"npm run build","publish:npm":"npm publish --access public","prepublish:next":"npm run build","publish:next":"npm publish --access public --tag next","test":"npm run test:integration","test:integration":"jest --config ./test/jest-e2e.config.json --runInBand","test:cov":"jest --config ./test/jest-e2e.config.json --runInBand --coverage","prerelease":"npm run build","release":"dotenv release-it --"},"_id":"@c12/nestjs-oauth2-server@0.1.0","_integrity":"sha512-oGUSd0gGSkbcKQqcPYQVpGTW4Nhdw5APhiRjjUkoTqiRBrnEqtPrj+tGaKAeH5aaz7RShB+hkyCWtS8EIQLHnA==","_resolved":"/private/var/folders/mb/zlrl_k_x7gl460rx443wy_040000gn/T/5542ea38e30d325b1552d848bfdfe4e7/c12-nestjs-oauth2-server-0.1.0.tgz","_from":"file:c12-nestjs-oauth2-server-0.1.0.tgz","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-oGUSd0gGSkbcKQqcPYQVpGTW4Nhdw5APhiRjjUkoTqiRBrnEqtPrj+tGaKAeH5aaz7RShB+hkyCWtS8EIQLHnA==","shasum":"28e9b5ad8edd5cddff307d3776190690ccd6996c","tarball":"https://registry.npmjs.org/@c12/nestjs-oauth2-server/-/nestjs-oauth2-server-0.1.0.tgz","fileCount":9,"unpackedSize":24689,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDeQRWz4Iog8KH2TeUAgB+wF8MbZ4R4R8Lg8K+AANrsdAIhAMzhCcqkEnn0Gbs5UwhKcbUdvT6F6dAZBLrqNAufRQ/3"}]},"_npmUser":{"name":"bradford","email":"bradford.toney@gmail.com"},"maintainers":[{"name":"bradford","email":"bradford.toney@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-oauth2-server_0.1.0_1718506922985_0.43257909429001273"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-16T03:02:02.817Z","0.1.0":"2024-06-16T03:02:03.205Z","modified":"2024-06-16T03:02:03.524Z"},"maintainers":[{"name":"bradford","email":"bradford.toney@gmail.com"}],"description":"A NestJS wrapper for oauth2-server","homepage":"https://github.com/boyuai/nestjs-oauth2-server#readme","keywords":["nestjs oauth2 server","nestjs oauth2","@nestjs/oauth2-server","nest oauth2 server","nestjs","nest"],"repository":{"type":"git","url":"git+https://github.com/boyuai/nestjs-oauth2-server.git"},"author":{"name":"B'Tunde Aromire"},"bugs":{"url":"https://github.com/boyuai/nestjs-oauth2-server/issues"},"license":"MIT","readme":"## NestJS OAuth2 Server\n\n<p align=\"center\">\n  <a href=\"http://nestjs.com/\" target=\"blank\"><img src=\"https://nestjs.com/img/logo-small.svg\" width=\"120\" alt=\"Nest Logo\" /></a>\n  <img src=\"https://github.com/boyuai/nestjs-oauth2-server/blob/master/oauth2.png?raw=true\" width=\"120\" alt=\"OAuth2 Logo\" />\n</p>\n\n<p align='center'>\n    <a href=\"https://www.npmjs.com/package/@boyuai/nestjs-oauth2-server\" target='_blank'><img alt=\"npm\" src=\"https://img.shields.io/npm/dm/@boyuai/nestjs-oauth2-server\" alt=\"NPM Downloads\"></a>\n    <!-- <a href=\"https://coveralls.io/github/toondaey/nestjs-oauth2-server\" target=\"_blank\" rel=\"noopener noreferrer\"><img alt=\"Coveralls github\" src=\"https://img.shields.io/coveralls/github/toondaey/nestjs-oauth2-server\"></a> -->\n    <a href=\"https://npmjs.com/@boyuai/nestjs-oauth2-server\" target=\"_blank\" rel=\"noopener noreferrer\"><img alt=\"npm version\" src=\"https://img.shields.io/npm/v/@boyuai/nestjs-oauth2-server?label=NPM&logo=NPM\"></a>\n    <a href=\"https://npmjs.com/@boyuai/nestjs-oauth2-server\" target=\"_blank\" rel=\"noopener noreferrer\"><img alt=\"LICENCE\" src=\"https://img.shields.io/npm/l/@boyuai/nestjs-oauth2-server\"></a>\n    <!-- <a href=\"https://circleci.com/gh/toondaey/nestjs-oauth2-server\" target=\"_blank\" rel=\"noopener noreferrer\"><img alt=\"CircleCI build\" src=\"https://img.shields.io/circleci/build/gh/toondaey/nestjs-oauth2-server/master\"></a> -->\n    <a href=\"https://www.npmjs.com/package/@boyuai/nestjs-oauth2-server\" target=\"_blank\" rel=\"noopener noreferrer\"><img alt=\"synk vulnerabilities\" src=\"https://img.shields.io/snyk/vulnerabilities/npm/@boyuai/nestjs-oauth2-server\"></a>\n</p>\n\n<p>\nA <a href=\"https://nestjs.com\" target='_blank'>NestJS</a> wrapper module for the <a href='https://oauth2-server.readthedocs.io/en/latest/index.html' target='_blank'>oauth2-server</a> package.\n</p>\n\n<details>\n<summary><strong>Table of content</strong> (click to expand)</summary>\n\n<!-- toc -->\n\n-   [Installation](#installation)\n-   [Configuration](#configuration)\n-   [Usage](#usage)\n-   [Learnings](#learnings)\n-   [Contributing](#contributing)\n    <!-- tocstop -->\n    </details>\n\n## Installation\n\nInstallation is as simple as running:\n\n`pnpm install @c12/nestjs-oauth2-server`\n\nor\n\n`yarn add @c12/nestjs-oauth2-server`.\n\n## Configuration\n\n1. Include the module as a dependency in the module where oauth will happen:\n\n`oauth2.module.ts`\n\n```ts\nimport { Module } from '@nestjs/common';\nimport { OAuth2ServerModule } from '@c12/nestjs-oauth2-server';\nimport { OAuth2Controller } from './oauth2.controller';\nimport { OAuth2ServiceModule } from './oauth2-service.module';\nimport { OAuth2Model } from './oauth2.model';\n\n@Module({\n  imports: [\n    OAuth2ServiceModule,\n    OAuth2ServerModule.forRoot({\n      imports: [OAuth2ServiceModule], // import your repository for OAuth2Model here\n      modelClass: OAuth2Model,\n    }),\n  ],\n  controllers: [OAuth2Controller],\n})\nexport class OAuth2Module {}\n```\n\nIn addition to the above the, **oauth2-server** requires a [model](https://oauth2-server.readthedocs.io/en/latest/model/overview.html) to create the server. This can be provided as a service from any part of the application. This should be able to fetch data about clients, users, token, and authorization codes. This **MUST** be a service decorated with the `Injectable` decorator.\n\n`oauth2.model.ts`\n\n```ts\nimport { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class OAuth2Model implements RequestAuthenticationModel {\n    getAccessToken() {}\n\n    verifyScope() {}\n    // ...\n    // check more codes in test/src/test-model.service.ts\n}\n```\n\n## Usage\n\nThe module also provides some nifty decorators to help with configuring the oauth2 handler endpoints. An example controller covering the entire array of decorators is given below\n\n`oauth2.controller.ts`\n\n```ts\nimport { Controller } from '@nestjs/common';\nimport {\n  OAuth2Authorization,\n  OAuth2Authorize,\n  OAuth2RenewToken,\n  OAuth2Token,\n} from '@c12/nestjs-oauth2-server';\n\n@Controller()\nexport class OAuth2Controller {\n    @Post()\n    @OAuth2Authenticate()\n    authenticateClient(@OAuth2Token() token: Token) {\n        return token;\n    }\n\n    @Post()\n    @OAuth2Authorize()\n    authorizeClient(\n        @OAuth2Authorization()\n        authorization: AuthorizationCode,\n    ) {\n        return authorization;\n    }\n\n    @Post()\n    @OAuth2RenewToken()\n    renewToken(@OAuth2Token() token: Token) {\n        return token;\n    }\n}\n```\n\n## Async Configuration\n\nThe module could also be included asynchronously using the `forRootAsync` method.\n\nExamples below:\n\n-   Using factory provider approach\n\n```ts\nimport { Module } from '@nestjs/common';\nimport {\n    OAuth2ServerModule,\n    IOAuth2ServerModuleOptions,\n} from '@c12/nestjs-oauth2-server';\n\n@Module({\n    imports: [\n        // ... other modules\n        OAuth2ServerModule.forRootAsync({\n            useFactory: (factory: IOAuth2ServerOptionsFactory) => ({}),\n            modelClass: YourModelService,\n        }),\n    ],\n})\nexport class YourModule {}\n```\n\n-   Using class or existing provider approach:\n\n`oauth2-server-config.service.ts`\n\n```ts\nimport {\n    IOAuth2ServerModuleOptions,\n    IOAuth2ServerOptionsFactory,\n} from '@c12/nestjs-oauth2-server';\nimport { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class OAuth2ServerConfigService\n    implements IOAuth2ServerOptionsFactory {\n    createOAuth2ServerOptions(): IOAuth2ServerModuleOptions {\n        return {};\n    }\n}\n```\n\nThe `OAuth2ServerConfigService` **SHOULD** implement the `IOAuth2ServerOptionsFactory`, **MUST** declare the `createOAuth2ServerOptions` method and **MUST** return `IOAuth2ServerModuleOptions` object.\n\n```ts\nimport { Module } from '@nestjs/common';\nimport { OAuth2ServerModule } from '@c12/nestjs-oauth2-server';\nimport { OAuth2ServerConfigService } from './oauth2-server-config.service.ts';\n\n@Module({\n    imports: [\n        // ... other modules\n        OAuth2ServerModule.forRootAsync({\n            useClass: OAuth2ServerConfigService,\n            modelClass: YourModelService,\n        }),\n    ],\n})\nexport class YourModule {}\n```\n\n## Learnings\n\nThe concept of OAuth2 can be further understood in this article [here](https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2). Also you can head over to the oauth2-server package [documentation](package).\n\n## Contributing\n\nSuggestions for improvement are welcomed, however, please adhere to the [contributing](./CONTRIBUTING.md) guidelines.\n\n[package]: https://oauth2-server.readthedocs.io/en/latest/index.html\n","readmeFilename":"README.md"}