Skip to content

Commit e797f63

Browse files
committed
support getting token via Bearer
1 parent 7afb5eb commit e797f63

File tree

5 files changed

+1251
-1113
lines changed

5 files changed

+1251
-1113
lines changed

examples/nestjs/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@
1111
"dev": "nest start --watch"
1212
},
1313
"dependencies": {
14-
"@nestjs/common": "^9.4.0",
15-
"@nestjs/core": "^9.4.0",
14+
"@nestjs/common": "^9.4.1",
15+
"@nestjs/core": "^9.4.1",
1616
"@nestjs/passport": "^9.0.3",
17-
"@nestjs/platform-express": "^9.4.0",
17+
"@nestjs/platform-express": "^9.4.1",
1818
"dotenv": "^16.0.3",
1919
"passport": "^0.6.0",
2020
"passport-google-oauth-token": "workspace:*",
2121
"reflect-metadata": "^0.1.13",
22-
"rxjs": "^7.2.0"
22+
"rxjs": "^7.8.1"
2323
},
2424
"devDependencies": {
25-
"@nestjs/cli": "^9.3.0",
26-
"@nestjs/schematics": "^9.1.0",
27-
"@types/express": "^4.17.13",
28-
"@types/node": "18.15.11",
29-
"source-map-support": "^0.5.20",
30-
"ts-loader": "^9.2.3",
31-
"ts-node": "^10.0.0",
25+
"@nestjs/cli": "^9.5.0",
26+
"@nestjs/schematics": "^9.2.0",
27+
"@types/express": "^4.17.17",
28+
"@types/node": "20.2.1",
29+
"source-map-support": "^0.5.21",
30+
"ts-loader": "^9.4.2",
31+
"ts-node": "^10.9.1",
3232
"tsconfig-paths": "4.2.0"
3333
}
3434
}

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
},
1717
"license": "MIT",
1818
"devDependencies": {
19-
"@rollup/plugin-commonjs": "^24.0.1",
19+
"@rollup/plugin-commonjs": "^25.0.0",
2020
"@rollup/plugin-json": "^6.0.0",
2121
"@rollup/plugin-node-resolve": "^15.0.2",
22-
"@rollup/plugin-typescript": "^11.1.0",
23-
"@typescript-eslint/eslint-plugin": "^5.57.1",
24-
"@typescript-eslint/parser": "^5.57.1",
25-
"eslint": "^8.38.0",
22+
"@rollup/plugin-typescript": "^11.1.1",
23+
"@typescript-eslint/eslint-plugin": "^5.59.6",
24+
"@typescript-eslint/parser": "^5.59.6",
25+
"eslint": "^8.41.0",
2626
"eslint-config-prettier": "^8.8.0",
2727
"eslint-plugin-prettier": "^4.2.1",
2828
"husky": "^8.0.3",
29-
"lint-staged": "^13.2.1",
30-
"prettier": "^2.8.7",
31-
"rollup": "^3.20.2",
29+
"lint-staged": "^13.2.2",
30+
"prettier": "^2.8.8",
31+
"rollup": "^3.22.0",
3232
"typescript": "^5.0.4"
3333
},
3434
"dependencies": {
35-
"tslib": "^2.5.0"
35+
"tslib": "^2.5.2"
3636
}
3737
}

packages/passport-google-oauth-token/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "passport-google-oauth-token",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Google access token authentication strategy for Passport",
55
"author": "Alpha",
66
"repository": {
@@ -42,6 +42,6 @@
4242
"@types/oauth": "^0.9.1",
4343
"@types/passport-oauth2": "^1.4.12",
4444
"oauth": "^0.10.0",
45-
"vitest": "^0.29.8"
45+
"vitest": "^0.31.1"
4646
}
4747
}

packages/passport-google-oauth-token/src/Strategy.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,26 @@ export default class GoogleOauthTokenStrategy extends OAuth2Strategy {
175175
});
176176
}
177177

178+
protected _lookupAuthorization(req: Request): string {
179+
if (!req.headers?.authorization) {
180+
return '';
181+
}
182+
183+
const matches = req.headers.authorization.match(/(\S+)\s+(\S+)/);
184+
185+
if (matches?.[1].toLowerCase() !== 'bearer') {
186+
return '';
187+
}
188+
189+
return matches?.[2] || '';
190+
}
191+
178192
protected _lookup(req: Request, field: string): string {
179193
return (
180194
(req.body && req.body[field]) ||
181195
(req.query && req.query[field]) ||
182-
(req.headers && req.headers[field])
196+
(req.headers && req.headers[field]) ||
197+
this._lookupAuthorization(req)
183198
);
184199
}
185200

0 commit comments

Comments
 (0)