Skip to content

Commit 2f97d32

Browse files
committed
update dependencies
1 parent 82b6918 commit 2f97d32

16 files changed

+172
-130
lines changed

.eslintrc.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
sourceType: 'module',
6+
},
7+
plugins: ['@typescript-eslint/eslint-plugin'],
8+
extends: [
9+
'plugin:@typescript-eslint/recommended',
10+
'plugin:prettier/recommended',
11+
],
12+
root: true,
13+
env: {
14+
node: true,
15+
jest: true,
16+
},
17+
ignorePatterns: ['.eslintrc.js'],
18+
rules: {
19+
'@typescript-eslint/interface-name-prefix': 'off',
20+
'@typescript-eslint/explicit-function-return-type': 'off',
21+
'@typescript-eslint/explicit-module-boundary-types': 'off',
22+
'@typescript-eslint/no-explicit-any': 'off',
23+
},
24+
};

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"arrowParens": "always",
5+
"printWidth": 100
6+
}

CHANGELOG.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
# Changelog
22

3-
## Version 1.0.0
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [2.0.0] - 2021-04-26
9+
10+
### Added
11+
- add checkRevoked option for jwt verification
12+
13+
### Changed
14+
15+
- Updated NestJS dependencies
16+
- Updated `firebase-admin` dependecy
17+
- Updated scripts. Now it's using [Nest Cli](https://docs.nestjs.com/cli/overview)
18+
19+
[2.0.0]: https://github.com/tfarras/nestjs-firebase-auth/releases/tag/2.0.0

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## Code Style
1111

12-
We use [Prettier](https://prettier.io/) and tslint to maintain code style and best practices.
12+
We use [Prettier](https://prettier.io/) and eslint to maintain code style and best practices.
1313
Please make sure your PR adheres to the guides by running:
1414

1515
```bash

nest-cli.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"language": "ts",
32
"collection": "@nestjs/schematics",
43
"sourceRoot": "src"
54
}

package.json

+45-29
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
"*.md"
1212
],
1313
"scripts": {
14-
"start:dev": "tsc -w",
15-
"build": "tsc",
16-
"prepare": "npm run build",
17-
"format": "prettier --write \"src/**/*.ts\"",
18-
"lint": "tslint -p tsconfig.json -c tslint.json",
14+
"prebuild": "rimraf dist",
15+
"build": "nest build",
16+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
17+
"start": "nest start",
18+
"start:dev": "nest start --watch",
19+
"start:debug": "nest start --debug --watch",
20+
"start:prod": "node dist/main",
21+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
1922
"test": "jest",
2023
"test:watch": "jest --watch",
2124
"test:cov": "jest --coverage",
25+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
2226
"test:e2e": "jest --config ./test/jest-e2e.json"
2327
},
2428
"keywords": [
@@ -43,34 +47,43 @@
4347
},
4448
"homepage": "https://github.com/tfarras/nestjs-firebase-auth#readme",
4549
"peerDependencies": {
46-
"@nestjs/common": "^6.0.0",
47-
"firebase-admin": "^8.10.0",
50+
"@nestjs/common": "^7.6.15",
51+
"@types/passport-jwt": "^3.0.5",
52+
"firebase-admin": "^9.6.0",
4853
"passport": "^0.4.1",
4954
"passport-jwt": "^4.0.0"
5055
},
5156
"devDependencies": {
52-
"@nestjs/common": "^6.0.0",
53-
"@nestjs/core": "^6.0.0",
54-
"@nestjs/platform-express": "^6.0.0",
55-
"@nestjs/testing": "6.1.1",
56-
"@types/express": "4.16.1",
57-
"@types/jest": "24.0.11",
58-
"@types/node": "11.13.4",
59-
"@types/supertest": "2.0.7",
60-
"rxjs": "^6.5.4",
61-
"jest": "24.7.1",
62-
"prettier": "1.17.0",
63-
"supertest": "4.0.2",
64-
"ts-jest": "24.0.2",
65-
"ts-node": "8.1.0",
66-
"tsc-watch": "2.2.1",
67-
"tsconfig-paths": "3.8.0",
68-
"tslint": "5.16.0",
69-
"typescript": "3.7.2",
70-
"firebase-admin": "^8.10.0",
57+
"@nestjs/cli": "^7.6.0",
58+
"@nestjs/common": "^7.6.15",
59+
"@nestjs/core": "^7.6.15",
60+
"@nestjs/platform-express": "^7.6.15",
61+
"@nestjs/schematics": "^7.3.0",
62+
"@nestjs/testing": "^7.6.15",
63+
"@types/express": "^4.17.11",
64+
"@types/jest": "^26.0.22",
65+
"@types/node": "^14.14.36",
66+
"@types/passport-jwt": "^3.0.5",
67+
"@types/supertest": "^2.0.10",
68+
"@typescript-eslint/eslint-plugin": "^4.19.0",
69+
"@typescript-eslint/parser": "^4.19.0",
70+
"eslint": "^7.22.0",
71+
"eslint-config-prettier": "^8.1.0",
72+
"eslint-plugin-prettier": "^3.3.1",
73+
"firebase-admin": "^9.6.0",
74+
"jest": "^26.6.3",
7175
"passport": "^0.4.1",
7276
"passport-jwt": "^4.0.0",
73-
"@types/passport-jwt": "^3.0.3"
77+
"prettier": "^2.2.1",
78+
"reflect-metadata": "^0.1.13",
79+
"rimraf": "^3.0.2",
80+
"rxjs": "^6.6.6",
81+
"supertest": "^6.1.3",
82+
"ts-jest": "^26.5.4",
83+
"ts-loader": "^8.0.18",
84+
"ts-node": "^9.1.1",
85+
"tsconfig-paths": "^3.9.0",
86+
"typescript": "^4.2.3"
7487
},
7588
"jest": {
7689
"moduleFileExtensions": [
@@ -79,11 +92,14 @@
7992
"ts"
8093
],
8194
"rootDir": "src",
82-
"testRegex": ".spec.ts$",
95+
"testRegex": ".*\\.spec\\.ts$",
8396
"transform": {
8497
"^.+\\.(t|j)s$": "ts-jest"
8598
},
99+
"collectCoverageFrom": [
100+
"**/*.(t|j)s"
101+
],
86102
"coverageDirectory": "../coverage",
87103
"testEnvironment": "node"
88104
}
89-
}
105+
}

src/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const UNAUTHORIZED = 'Unauthorized';
2-
export const FIREBASE_AUTH = 'FIREBASE_AUTH';
2+
export const FIREBASE_AUTH = 'FIREBASE_AUTH';

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './constants';
22
export * from './passport-firebase.strategy';
33
export * from './user.type';
4-
export * from './interface';
4+
export * from './interface';

src/interface/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './object-literal.interface';
2-
export * from './options.interface';
2+
export * from './options.interface';
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export interface ObjectLiteral {
22
[key: string]: any;
3-
}
3+
}

src/interface/options.interface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import { JwtFromRequestFunction } from 'passport-jwt';
33
export interface FirebaseAuthStrategyOptions {
44
extractor: JwtFromRequestFunction;
55
checkRevoked?: boolean;
6-
}
6+
}

src/passport-firebase.strategy.ts

+68-67
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,68 @@
1-
import { Logger } from '@nestjs/common';
2-
import { JwtFromRequestFunction } from 'passport-jwt';
3-
import { Strategy } from "passport-strategy";
4-
import { Request } from "express";
5-
import { FirebaseAuthStrategyOptions } from './interface/options.interface';
6-
import { UNAUTHORIZED, FIREBASE_AUTH } from './constants';
7-
import { FirebaseUser } from './user.type';
8-
import * as admin from 'firebase-admin';
9-
10-
11-
export class FirebaseAuthStrategy extends Strategy {
12-
readonly name = FIREBASE_AUTH;
13-
private checkRevoked = false;
14-
15-
constructor(
16-
options: FirebaseAuthStrategyOptions,
17-
private extractor: JwtFromRequestFunction,
18-
private logger = new Logger(FirebaseAuthStrategy.name),
19-
) {
20-
super();
21-
22-
if (!options.extractor) {
23-
throw new Error('\n Extractor is not a function. You should provide an extractor. \n Read the docs: https://github.com/tfarras/nestjs-firebase-auth#readme');
24-
}
25-
26-
this.extractor = options.extractor;
27-
this.checkRevoked = options.checkRevoked;
28-
}
29-
30-
async validate(payload: FirebaseUser): Promise<any> {
31-
return payload;
32-
}
33-
34-
authenticate(req: Request): void {
35-
const idToken = this.extractor(req);
36-
37-
if (!idToken) {
38-
this.fail(UNAUTHORIZED, 401);
39-
40-
return;
41-
}
42-
43-
try {
44-
admin.auth()
45-
.verifyIdToken(idToken, this.checkRevoked)
46-
.then((res) => this.validateDecodedIdToken(res))
47-
.catch((err) => {
48-
this.fail({ err }, 401);
49-
});
50-
}
51-
catch (e) {
52-
this.logger.error(e);
53-
54-
this.fail(e, 401);
55-
}
56-
}
57-
58-
private async validateDecodedIdToken(decodedIdToken: FirebaseUser) {
59-
const result = await this.validate(decodedIdToken);
60-
61-
if (result) {
62-
this.success(result);
63-
}
64-
65-
this.fail(UNAUTHORIZED, 401);
66-
}
67-
}
1+
import { Logger } from '@nestjs/common';
2+
import { JwtFromRequestFunction } from 'passport-jwt';
3+
import { Strategy } from 'passport-strategy';
4+
import { Request } from 'express';
5+
import { FirebaseAuthStrategyOptions } from './interface/options.interface';
6+
import { UNAUTHORIZED, FIREBASE_AUTH } from './constants';
7+
import { FirebaseUser } from './user.type';
8+
import * as admin from 'firebase-admin';
9+
10+
export class FirebaseAuthStrategy extends Strategy {
11+
readonly name = FIREBASE_AUTH;
12+
private checkRevoked = false;
13+
14+
constructor(
15+
options: FirebaseAuthStrategyOptions,
16+
private extractor: JwtFromRequestFunction,
17+
private logger = new Logger(FirebaseAuthStrategy.name),
18+
) {
19+
super();
20+
21+
if (!options.extractor) {
22+
throw new Error(
23+
'\n Extractor is not a function. You should provide an extractor. \n Read the docs: https://github.com/tfarras/nestjs-firebase-auth#readme',
24+
);
25+
}
26+
27+
this.extractor = options.extractor;
28+
this.checkRevoked = options.checkRevoked;
29+
}
30+
31+
async validate(payload: FirebaseUser): Promise<any> {
32+
return payload;
33+
}
34+
35+
authenticate(req: Request): void {
36+
const idToken = this.extractor(req);
37+
38+
if (!idToken) {
39+
this.fail(UNAUTHORIZED, 401);
40+
41+
return;
42+
}
43+
44+
try {
45+
admin
46+
.auth()
47+
.verifyIdToken(idToken, this.checkRevoked)
48+
.then((res) => this.validateDecodedIdToken(res))
49+
.catch((err) => {
50+
this.fail({ err }, 401);
51+
});
52+
} catch (e) {
53+
this.logger.error(e);
54+
55+
this.fail(e, 401);
56+
}
57+
}
58+
59+
private async validateDecodedIdToken(decodedIdToken: FirebaseUser) {
60+
const result = await this.validate(decodedIdToken);
61+
62+
if (result) {
63+
this.success(result);
64+
}
65+
66+
this.fail(UNAUTHORIZED, 401);
67+
}
68+
}

src/user.type.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import * as admin from 'firebase-admin';
22

3-
export type FirebaseUser = admin.auth.DecodedIdToken;
3+
export type FirebaseUser = admin.auth.DecodedIdToken;
-3.42 KB
Binary file not shown.

tsconfig.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
"removeComments": true,
66
"emitDecoratorMetadata": true,
77
"experimentalDecorators": true,
8-
"target": "es6",
9-
"sourceMap": false,
8+
"allowSyntheticDefaultImports": true,
9+
"target": "es2017",
10+
"sourceMap": true,
1011
"outDir": "./dist",
11-
"rootDir": "./src",
1212
"baseUrl": "./",
13-
"noLib": false
14-
},
15-
"include": ["src/**/*.ts"],
16-
"exclude": ["node_modules"]
13+
"incremental": true
14+
}
1715
}

tslint.json

-18
This file was deleted.

0 commit comments

Comments
 (0)