{"_id":"@tfarras/nestjs-firebase-auth","_rev":"3-9fb65dde8e9e5a2ef1c478cece6587ca","name":"@tfarras/nestjs-firebase-auth","dist-tags":{"latest":"2.0.0","next":"2.0.0-0"},"versions":{"1.0.0":{"name":"@tfarras/nestjs-firebase-auth","version":"1.0.0","description":"NestJS Passport Strategy for Firebase Auth using Firebase Admin SDK","author":{"name":"Taimoor Farras","email":"farrastaimoor@gmail.com"},"main":"dist/index.js","license":"MIT","scripts":{"start:dev":"tsc -w","build":"tsc","prepare":"npm run build","format":"prettier --write \"src/**/*.ts\"","lint":"tslint -p tsconfig.json -c tslint.json","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage","test:e2e":"jest --config ./test/jest-e2e.json"},"keywords":["nestjs","firebase","firebase-admin","firebase-auth","passport","passport-jwt","auth","authentication"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/tfarras/nestjs-firebase-auth.git"},"bugs":{"url":"https://github.com/tfarras/nestjs-firebase-auth/issues"},"homepage":"https://github.com/tfarras/nestjs-firebase-auth#readme","peerDependencies":{"@nestjs/common":"^6.0.0","firebase-admin":"^8.10.0","passport":"^0.4.1","passport-jwt":"^4.0.0"},"devDependencies":{"@nestjs/common":"^6.0.0","@nestjs/core":"^6.0.0","@nestjs/platform-express":"^6.0.0","@nestjs/testing":"6.1.1","@types/express":"4.16.1","@types/jest":"24.0.11","@types/node":"11.13.4","@types/supertest":"2.0.7","rxjs":"^6.5.4","jest":"24.7.1","prettier":"1.17.0","supertest":"4.0.2","ts-jest":"24.0.2","ts-node":"8.1.0","tsc-watch":"2.2.1","tsconfig-paths":"3.8.0","tslint":"5.16.0","typescript":"3.7.2","firebase-admin":"^8.10.0","passport":"^0.4.1","passport-jwt":"^4.0.0","@types/passport-jwt":"^3.0.3"},"jest":{"moduleFileExtensions":["js","json","ts"],"rootDir":"src","testRegex":".spec.ts$","transform":{"^.+\\.(t|j)s$":"ts-jest"},"coverageDirectory":"../coverage","testEnvironment":"node"},"gitHead":"7808c03c787ffa35ef922d4855ebc22272ae7e50","_id":"@tfarras/nestjs-firebase-auth@1.0.0","_nodeVersion":"13.10.1","_npmVersion":"6.14.2","dist":{"integrity":"sha512-Zklaxjl2y4p91QrALjesuN+DnUhTLe5Ad6EZrQ8NJalF0gwgWtq1P9wV5z2ZpXTsnd5+t6a9pyQpcc0wFzwxKA==","shasum":"6445bb3f628169c0a0c268fe45ca70e772f35a33","tarball":"https://registry.npmjs.org/@tfarras/nestjs-firebase-auth/-/nestjs-firebase-auth-1.0.0.tgz","fileCount":18,"unpackedSize":11691,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJekjUACRA9TVsSAnZWagAAutcP/0ICAmRacQ38Yib/I4eq\nulMJYxfJXzYSTYX0x+MvGWB1U/UxOPVhurw+Wn6h1OwtHJM+h3DsBkbdD+4u\nRSpW8O5oYUXUrWBjcjrX7k+0DrMYc/C4hA/NQ/aa9Qq/S+C8SN3L0N4GSS+9\nb3cKVe0zg6iMaLj6PsYwaDDPwAxHQtPB8dRFoAIQD6xOfMQvKlULZv+dNNps\nimjeCfGxDIkLDwif4IiPpSVQmaBvnJOfjmDKjJ06wcF71Tn0i501ylxK92AO\ncQFN3QttezR9/y2EwY+haezr4KJhztVc6Q99CZ6A3Kq3WACFX6JBv1Nuz21A\nqnMrc2+BHOi2LqCXAuINx5TQXeRUEcCD8n9idymzBBzHxAWboXUjDwn2if68\nrl4ivIPwibiP7pUyOb1zaYyCFft04dl8tSwhFl0qLO7c5hw2WI/QnBa8iHrj\n/TKMpZ+6kIiwD/UJOewZEyoRYRg1fYOcZZUGrUysjxIgVcsvGV7lg5VftUuG\nOpGzWlUJacVXduBpmgyxzUNpViDMvC27O98ZG7bt3u8YzvcrH24w91xD0Swr\nofsep+Rm3BWrmi2EudF7Z/ceX1LEY8/SHwNyqty5obZdbSQ2DyPyvkFFaoEP\n29QlVrEQTLTX9izMg8WpIuv9u6g7SV0ScMb8+N0rX4ipm3AD/noaYclcpmMo\nZ1kq\r\n=xPCV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAZMa8xXUg3c6NGhPGKe3RxKx3Fsj982uxhqys8eKBUSAiEAkUDTl30EkuEDDgrXKrofZcKLzUjRoo4PzOJ6M2lK0GI="}]},"maintainers":[{"name":"tfarras","email":"farrastaimoor@gmail.com"}],"_npmUser":{"name":"tfarras","email":"farrastaimoor@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-firebase-auth_1.0.0_1586640127926_0.42732633860296065"},"_hasShrinkwrap":false},"2.0.0-0":{"name":"@tfarras/nestjs-firebase-auth","version":"2.0.0-0","description":"NestJS Passport Strategy for Firebase Auth using Firebase Admin SDK","author":{"name":"Taimoor Farras","email":"farrastaimoor@gmail.com"},"readmeFilename":"README.md","main":"dist/index.js","license":"MIT","scripts":{"prebuild":"rimraf dist","build":"nest build","format":"prettier --write \"src/**/*.ts\" \"test/**/*.ts\"","start":"nest start","start:dev":"nest start --watch","start:debug":"nest start --debug --watch","start:prod":"node dist/main","lint":"eslint \"{src,apps,libs,test}/**/*.ts\" --fix","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage","test:debug":"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand","test:e2e":"jest --config ./test/jest-e2e.json"},"keywords":["nestjs","firebase","firebase-admin","firebase-auth","passport","passport-jwt","auth","authentication"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/tfarras/nestjs-firebase-auth.git"},"bugs":{"url":"https://github.com/tfarras/nestjs-firebase-auth/issues"},"homepage":"https://github.com/tfarras/nestjs-firebase-auth#readme","peerDependencies":{"@nestjs/common":"^7.6.15","@types/passport-jwt":"^3.0.5","firebase-admin":"^9.6.0","passport":"^0.4.1","passport-jwt":"^4.0.0"},"devDependencies":{"@nestjs/cli":"^7.6.0","@nestjs/common":"^7.6.15","@nestjs/core":"^7.6.15","@nestjs/platform-express":"^7.6.15","@nestjs/schematics":"^7.3.0","@nestjs/testing":"^7.6.15","@types/express":"^4.17.11","@types/jest":"^26.0.22","@types/node":"^14.14.36","@types/passport-jwt":"^3.0.5","@types/supertest":"^2.0.10","@typescript-eslint/eslint-plugin":"^4.19.0","@typescript-eslint/parser":"^4.19.0","eslint":"^7.22.0","eslint-config-prettier":"^8.1.0","eslint-plugin-prettier":"^3.3.1","firebase-admin":"^9.6.0","jest":"^26.6.3","passport":"^0.4.1","passport-jwt":"^4.0.0","prettier":"^2.2.1","reflect-metadata":"^0.1.13","rimraf":"^3.0.2","rxjs":"^6.6.6","supertest":"^6.1.3","ts-jest":"^26.5.4","ts-loader":"^8.0.18","ts-node":"^9.1.1","tsconfig-paths":"^3.9.0","typescript":"^4.2.3"},"jest":{"moduleFileExtensions":["js","json","ts"],"rootDir":"src","testRegex":".*\\.spec\\.ts$","transform":{"^.+\\.(t|j)s$":"ts-jest"},"collectCoverageFrom":["**/*.(t|j)s"],"coverageDirectory":"../coverage","testEnvironment":"node"},"readme":"#\n\n<div align=\"center\">\n  <a href=\"http://nestjs.com/\" target=\"_blank\">\n    <img src=\"https://nestjs.com/img/logo_text.svg\" width=\"150\" alt=\"Nest Logo\" />\n  </a>\n</div>\n\n<h3 align=\"center\">NestJS Passport Strategy for Firebase Auth using Firebase Admin SDK</h3>\n\n<div align=\"center\">\n  <a href=\"https://nestjs.com\" target=\"_blank\">\n    <img src=\"https://img.shields.io/badge/built%20with-NestJs-red.svg\" alt=\"Built with NestJS\">\n  </a>\n</div>\n\n# Installation\n\n## Install peer dependencies\n\n```bash\nnpm install passport passport-jwt\nnpm install --save-dev @types/passport-jwt\n```\n\n## Install `@nestjs/passport` for authentication\n\n```bash\nnpm install @nestjs/passport\n```\n\n## Install strategy\n\n```bash\nnpm install @tfarras/nestjs-firebase-auth\n```\n\n# Important\n\nTo work with Firebase Auth you need to configure and initialize your firebase app. For this purpose you can use my [module for firebase-admin](https://github.com/tfarras/nestjs-firebase-admin).\n\n# Create strategy\n\n```typescript\nimport { Injectable } from \"@nestjs/common\";\nimport { PassportStrategy } from \"@nestjs/passport\";\nimport { ExtractJwt } from 'passport-jwt';\nimport { FirebaseAuthStrategy } from '@tfarras/nestjs-firebase-auth';\n\n@Injectable()\nexport class FirebaseStrategy extends PassportStrategy(FirebaseAuthStrategy, 'firebase') {\n  public constructor() {\n    super({\n      extractor: ExtractJwt.fromAuthHeaderAsBearerToken(),\n    });\n  }\n}\n```\n\nNote: You should provide an extractor. More information about passport-jwt extractors you can find here: [http://www.passportjs.org/packages/passport-jwt/#included-extractors](http://www.passportjs.org/packages/passport-jwt/#included-extractors)\n\n# Create `AuthModule` and provide created strategy\n\n```typescript\nimport { Module } from \"@nestjs/common\";\nimport { PassportModule } from \"@nestjs/passport\";\nimport { FirebaseStrategy } from \"./firebase.strategy\";\n\n@Module({\n  imports: [PassportModule],\n  providers: [FirebaseStrategy],\n  exports: [FirebaseStrategy],\n  controllers: [],\n})\nexport class AuthModule { }\n```\n\n# Import `AuthModule` into `AppModule`\n\n```typescript\nimport { FirebaseAdminCoreModule } from '@tfarras/nestjs-firebase-admin';\nimport { Module } from '@nestjs/common';\nimport { ConfigModule, ConfigService } from 'nestjs-config';\nimport { AppController } from './app.controller';\nimport { AppService } from './app.service';\nimport { AuthModule } from './auth/auth.module';\nimport * as path from 'path';\n\n@Module({\n  imports: [\n    ConfigModule.load(path.resolve(__dirname, 'config', '**', '!(*.d).{ts,js}')),\n    FirebaseAdminCoreModule.forRootAsync({\n      useFactory: (config: ConfigService) => config.get('firebase'),\n      inject: [ConfigService],\n    }),\n    AuthModule,\n  ],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule { }\n\n```\n\n# Protect your routes\n\n```typescript\nimport { Controller, Get, Inject, UseGuards } from '@nestjs/common';\nimport { AuthGuard } from '@nestjs/passport';\nimport { FirebaseAdminSDK, FIREBASE_ADMIN_INJECT } from '@tfarras/nestjs-firebase-admin';\nimport { AppService } from './app.service';\n\n@Controller()\nexport class AppController {\n  constructor(\n    private readonly appService: AppService,\n    @Inject(FIREBASE_ADMIN_INJECT) private readonly fireSDK: FirebaseAdminSDK,\n  ) { }\n\n  @Get()\n  @UseGuards(AuthGuard('firebase'))\n  getHello() {\n    return this.fireSDK.auth().listUsers();\n  }\n}\n\n```\n\n# Custom second validation\n\nIn cases when you want to validate also if user exists in your database, or anything else after successfull Firebase validation you can define custom `validate` method in your strategy.\n\n## Example\n\n```typescript\nimport { Injectable } from \"@nestjs/common\";\nimport { PassportStrategy } from \"@nestjs/passport\";\nimport { FirebaseAuthStrategy, FirebaseUser } from '@tfarras/nestjs-firebase-auth';\nimport { ExtractJwt } from 'passport-jwt';\n\n@Injectable()\nexport class FirebaseStrategy extends PassportStrategy(FirebaseAuthStrategy, 'firebase') {\n  public constructor() {\n    super({\n      extractor: ExtractJwt.fromAuthHeaderAsBearerToken(),\n    });\n  }\n\n  async validate(payload: FirebaseUser): Promise<FirebaseUser> {\n    // Do here whatever you want and return your user\n    return payload;\n  }\n}\n```\n","gitHead":"6f690350148675fe6c11141e98570eb30ffb9daf","_id":"@tfarras/nestjs-firebase-auth@2.0.0-0","_nodeVersion":"14.16.0","_npmVersion":"7.10.0","dist":{"integrity":"sha512-L7unwA8pYBZ8TSKHnEbJfceCUkX3iEgHWwTXSyg31Gb9ZwuMlW9/m4ELF3ekmumfrVliMtzhJW+eg45DHsi/4g==","shasum":"e9fffb74e44e766bb1fa0bf5ca219c7d8361a87b","tarball":"https://registry.npmjs.org/@tfarras/nestjs-firebase-auth/-/nestjs-firebase-auth-2.0.0-0.tgz","fileCount":26,"unpackedSize":357751,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJghuSVCRA9TVsSAnZWagAA3MEQAIYatjzzw3iIwPMbFW8e\n0Ralv5tPr5Pe9RNZPxtQXS59aUQa+zvOMytleUfL6EMUriY8WUpU4mMUeng3\nm0cSGbWYaVeSrrg5fldQh298FA+JxG8Xm1+VaNI0YEGOJQF1L31Kodc47wQp\n9p/hFv0YKFUcrNv2izMnE9eGVxVrofuZQjVGvGNMhGfMZ5lphaSlNHoxKqqg\nrl1tkbOdM9wLE1yXLZ4kgzuIvf9cZEvrvEY6FOh1QOHV7DjB8L0IoBLWO56i\nv3dhF/Cp2i3FRRdec0twoTFB7EDnGkISfW3qRv3OlUjJsnLb92j2nolSXBt2\nhpyt1Hn0jND31DdTkYP4JknaBbmiBnUfBOZDrovJaOKTXISo6Mx7+KmvMbIc\nD5ptcpi6UeQSR5XN5z62IZgjMuX4VFgjFyshMZS7mx9yrc6+atUSz62sRCmL\nRln+lKpdrpbXSATWH76j2xMllVnHWImlj4rfJj1bPTNckQmoHefdIXAndwDC\nmS0vVHXfUOIOgWGBKeKc45PjIHwjGRzZwJCMQ+se34KU8WbA16HHuRk6dpHK\nKz617/+Umglx57imXPeeA7nY/2wtVrv9WZYKbeD2P943vpDzgKsTH0YuUq3T\nQWcr3gZlFPUjizW2b/Y4eBIGS+LMyCejK9YG8CnazlDHWPImBlXgc79Xi3NJ\nBOIg\r\n=vXPI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCTvZ6UgRDNhwDqQuZy1AEV8hotbhfAbbS2cHNTK4N1mwIgdpsxXi2REXRGuxXz3kPXSTQhFbXO5oJ7QrgpwLeXgl0="}]},"_npmUser":{"name":"tfarras","email":"farrastaimoor@gmail.com"},"directories":{},"maintainers":[{"name":"tfarras","email":"farrastaimoor@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-firebase-auth_2.0.0-0_1619453076945_0.8746796236487691"},"_hasShrinkwrap":false},"2.0.0":{"name":"@tfarras/nestjs-firebase-auth","version":"2.0.0","description":"NestJS Passport Strategy for Firebase Auth using Firebase Admin SDK","author":{"name":"Taimoor Farras","email":"farrastaimoor@gmail.com"},"main":"dist/index.js","license":"MIT","scripts":{"prebuild":"rimraf dist","build":"nest build","format":"prettier --write \"src/**/*.ts\" \"test/**/*.ts\"","start":"nest start","start:dev":"nest start --watch","start:debug":"nest start --debug --watch","start:prod":"node dist/main","lint":"eslint \"{src,apps,libs,test}/**/*.ts\" --fix","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage","test:debug":"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand","test:e2e":"jest --config ./test/jest-e2e.json"},"keywords":["nestjs","firebase","firebase-admin","firebase-auth","passport","passport-jwt","auth","authentication"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/tfarras/nestjs-firebase-auth.git"},"bugs":{"url":"https://github.com/tfarras/nestjs-firebase-auth/issues"},"homepage":"https://github.com/tfarras/nestjs-firebase-auth#readme","peerDependencies":{"@nestjs/common":"^7.6.15","@types/passport-jwt":"^3.0.5","firebase-admin":"^9.6.0","passport":"^0.4.1","passport-jwt":"^4.0.0"},"devDependencies":{"@nestjs/cli":"^7.6.0","@nestjs/common":"^7.6.15","@nestjs/core":"^7.6.15","@nestjs/platform-express":"^7.6.15","@nestjs/schematics":"^7.3.0","@nestjs/testing":"^7.6.15","@types/express":"^4.17.11","@types/jest":"^26.0.22","@types/node":"^14.14.36","@types/passport-jwt":"^3.0.5","@types/supertest":"^2.0.10","@typescript-eslint/eslint-plugin":"^4.19.0","@typescript-eslint/parser":"^4.19.0","eslint":"^7.22.0","eslint-config-prettier":"^8.1.0","eslint-plugin-prettier":"^3.3.1","firebase-admin":"^9.6.0","jest":"^26.6.3","passport":"^0.4.1","passport-jwt":"^4.0.0","prettier":"^2.2.1","reflect-metadata":"^0.1.13","rimraf":"^3.0.2","rxjs":"^6.6.6","supertest":"^6.1.3","ts-jest":"^26.5.4","ts-loader":"^8.0.18","ts-node":"^9.1.1","tsconfig-paths":"^3.9.0","typescript":"^4.2.3"},"jest":{"moduleFileExtensions":["js","json","ts"],"rootDir":"src","testRegex":".*\\.spec\\.ts$","transform":{"^.+\\.(t|j)s$":"ts-jest"},"collectCoverageFrom":["**/*.(t|j)s"],"coverageDirectory":"../coverage","testEnvironment":"node"},"gitHead":"635bf31f9010da8b7debac8364c5af869485c22e","_id":"@tfarras/nestjs-firebase-auth@2.0.0","_nodeVersion":"14.16.0","_npmVersion":"7.10.0","dist":{"integrity":"sha512-uZB/e/STnhSf1lrtJWkq3ORx1thZlRa9aNNtb/vRMHweV6EocvShuhvaJTJVEPhtvqGul2HiokwnOhoTgXaacA==","shasum":"4599a1444ab71b11beb3122c9cf11ddca06b8857","tarball":"https://registry.npmjs.org/@tfarras/nestjs-firebase-auth/-/nestjs-firebase-auth-2.0.0.tgz","fileCount":26,"unpackedSize":357767,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJghusyCRA9TVsSAnZWagAAh44P/i63nsXT06pXTZSKaZUN\nlxQPDVaglvk7HW+0bE/zUD1yDAg0KZptYGEWaE/uxbo0jJ2O/TlGNV2WUyOD\nHFx140E13YVIQwNMCpIpb8lTCHPLVm1PN+yS6L7Ds8fjtWu1f5/AHYwyI22l\nLiJS7KImtDluHJYA7zHT/WYsy8O+i6pSBussC4V3t8CVOlGVyrPKfybvIa8B\nVVwsTZciaWmuEMHn2gqPm2zZbsyEdSKbSl7cOleBqKknrzxwv9xsBlVivZhD\nU/ke/uN0ERrscKxFWwwert/xyeUu5d+zbzO/1BxvzjUl4K4btzExQTCejfRr\n79mLcd57fmPDcHtQfIVx74+HQP2m7Df+XS0+LwAgtYZxmChBdJaARq7kbSTh\n3CMLKIQtDzVok5rUj8m7wTbrvEQ729GX+4exzCpcIPicRzsvOiQ9VeW4SDzh\nqtfYxYMo14mkDhX7199dScI6H+MYyHFBhw3XiVvFZe9hlX6/6moQAbcu13eT\n24HCqHz3VHt9aitqwMQGtXnYdjmFzPa4i8ChMqoqOFOmMuIjCSeVGX50/tQ1\nqDDGWAQQsZ3hQ1iF9VxjmeXq7CIZSIx9P0f0B3A4g9IROL5tMVMgP08s8Z/7\ngq8DOUDgP7psIZjkUENIe7KRKzErqmsoxeJ0n/YVFz5/iYnx6FLDlisUPHSY\nLT39\r\n=QB70\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCf+yx006uWLFmYTU8WjilCUPiZXibnhrDbk6xBRLPvaQIhALe8Y6GPxToUsZ6J7IVCH6uTBc6AP8XW668HRx729T6b"}]},"_npmUser":{"name":"tfarras","email":"farrastaimoor@gmail.com"},"directories":{},"maintainers":[{"name":"tfarras","email":"farrastaimoor@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-firebase-auth_2.0.0_1619454769822_0.505703341163575"},"_hasShrinkwrap":false}},"time":{"created":"2020-04-11T21:22:07.889Z","1.0.0":"2020-04-11T21:22:08.055Z","modified":"2022-04-07T05:26:29.476Z","2.0.0-0":"2021-04-26T16:04:37.121Z","2.0.0":"2021-04-26T16:32:50.018Z"},"maintainers":[{"name":"tfarras","email":"farrastaimoor@gmail.com"}],"description":"NestJS Passport Strategy for Firebase Auth using Firebase Admin SDK","homepage":"https://github.com/tfarras/nestjs-firebase-auth#readme","keywords":["nestjs","firebase","firebase-admin","firebase-auth","passport","passport-jwt","auth","authentication"],"repository":{"type":"git","url":"git+https://github.com/tfarras/nestjs-firebase-auth.git"},"author":{"name":"Taimoor Farras","email":"farrastaimoor@gmail.com"},"bugs":{"url":"https://github.com/tfarras/nestjs-firebase-auth/issues"},"license":"MIT","readme":"#\n\n<div align=\"center\">\n  <a href=\"http://nestjs.com/\" target=\"_blank\">\n    <img src=\"https://nestjs.com/img/logo_text.svg\" width=\"150\" alt=\"Nest Logo\" />\n  </a>\n</div>\n\n<h3 align=\"center\">NestJS Passport Strategy for Firebase Auth using Firebase Admin SDK</h3>\n\n<div align=\"center\">\n  <a href=\"https://nestjs.com\" target=\"_blank\">\n    <img src=\"https://img.shields.io/badge/built%20with-NestJs-red.svg\" alt=\"Built with NestJS\">\n  </a>\n</div>\n\n# Installation\n\n## Install peer dependencies\n\n```bash\nnpm install passport passport-jwt\nnpm install --save-dev @types/passport-jwt\n```\n\n## Install `@nestjs/passport` for authentication\n\n```bash\nnpm install @nestjs/passport\n```\n\n## Install strategy\n\n```bash\nnpm install @tfarras/nestjs-firebase-auth\n```\n\n# Important\n\nTo work with Firebase Auth you need to configure and initialize your firebase app. For this purpose you can use my [module for firebase-admin](https://github.com/tfarras/nestjs-firebase-admin).\n\n# Create strategy\n\n```typescript\nimport { Injectable } from \"@nestjs/common\";\nimport { PassportStrategy } from \"@nestjs/passport\";\nimport { ExtractJwt } from 'passport-jwt';\nimport { FirebaseAuthStrategy } from '@tfarras/nestjs-firebase-auth';\n\n@Injectable()\nexport class FirebaseStrategy extends PassportStrategy(FirebaseAuthStrategy, 'firebase') {\n  public constructor() {\n    super({\n      extractor: ExtractJwt.fromAuthHeaderAsBearerToken(),\n    });\n  }\n}\n```\n\nNote: You should provide an extractor. More information about passport-jwt extractors you can find here: [http://www.passportjs.org/packages/passport-jwt/#included-extractors](http://www.passportjs.org/packages/passport-jwt/#included-extractors)\n\n# Create `AuthModule` and provide created strategy\n\n```typescript\nimport { Module } from \"@nestjs/common\";\nimport { PassportModule } from \"@nestjs/passport\";\nimport { FirebaseStrategy } from \"./firebase.strategy\";\n\n@Module({\n  imports: [PassportModule],\n  providers: [FirebaseStrategy],\n  exports: [FirebaseStrategy],\n  controllers: [],\n})\nexport class AuthModule { }\n```\n\n# Import `AuthModule` into `AppModule`\n\n```typescript\nimport { FirebaseAdminCoreModule } from '@tfarras/nestjs-firebase-admin';\nimport { Module } from '@nestjs/common';\nimport { ConfigModule, ConfigService } from 'nestjs-config';\nimport { AppController } from './app.controller';\nimport { AppService } from './app.service';\nimport { AuthModule } from './auth/auth.module';\nimport * as path from 'path';\n\n@Module({\n  imports: [\n    ConfigModule.load(path.resolve(__dirname, 'config', '**', '!(*.d).{ts,js}')),\n    FirebaseAdminCoreModule.forRootAsync({\n      useFactory: (config: ConfigService) => config.get('firebase'),\n      inject: [ConfigService],\n    }),\n    AuthModule,\n  ],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule { }\n\n```\n\n# Protect your routes\n\n```typescript\nimport { Controller, Get, Inject, UseGuards } from '@nestjs/common';\nimport { AuthGuard } from '@nestjs/passport';\nimport { FirebaseAdminSDK, FIREBASE_ADMIN_INJECT } from '@tfarras/nestjs-firebase-admin';\nimport { AppService } from './app.service';\n\n@Controller()\nexport class AppController {\n  constructor(\n    private readonly appService: AppService,\n    @Inject(FIREBASE_ADMIN_INJECT) private readonly fireSDK: FirebaseAdminSDK,\n  ) { }\n\n  @Get()\n  @UseGuards(AuthGuard('firebase'))\n  getHello() {\n    return this.fireSDK.auth().listUsers();\n  }\n}\n\n```\n\n# Custom second validation\n\nIn cases when you want to validate also if user exists in your database, or anything else after successfull Firebase validation you can define custom `validate` method in your strategy.\n\n## Example\n\n```typescript\nimport { Injectable } from \"@nestjs/common\";\nimport { PassportStrategy } from \"@nestjs/passport\";\nimport { FirebaseAuthStrategy, FirebaseUser } from '@tfarras/nestjs-firebase-auth';\nimport { ExtractJwt } from 'passport-jwt';\n\n@Injectable()\nexport class FirebaseStrategy extends PassportStrategy(FirebaseAuthStrategy, 'firebase') {\n  public constructor() {\n    super({\n      extractor: ExtractJwt.fromAuthHeaderAsBearerToken(),\n    });\n  }\n\n  async validate(payload: FirebaseUser): Promise<FirebaseUser> {\n    // Do here whatever you want and return your user\n    return payload;\n  }\n}\n```\n","readmeFilename":"README.md"}