Skip to content

Commit

Permalink
support getting token via Bearer
Browse files Browse the repository at this point in the history
  • Loading branch information
zgid123 committed May 21, 2023
1 parent 7afb5eb commit e797f63
Show file tree
Hide file tree
Showing 5 changed files with 1,251 additions and 1,113 deletions.
22 changes: 11 additions & 11 deletions examples/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
"dev": "nest start --watch"
},
"dependencies": {
"@nestjs/common": "^9.4.0",
"@nestjs/core": "^9.4.0",
"@nestjs/common": "^9.4.1",
"@nestjs/core": "^9.4.1",
"@nestjs/passport": "^9.0.3",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/platform-express": "^9.4.1",
"dotenv": "^16.0.3",
"passport": "^0.6.0",
"passport-google-oauth-token": "workspace:*",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0"
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^9.3.0",
"@nestjs/schematics": "^9.1.0",
"@types/express": "^4.17.13",
"@types/node": "18.15.11",
"source-map-support": "^0.5.20",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"@nestjs/cli": "^9.5.0",
"@nestjs/schematics": "^9.2.0",
"@types/express": "^4.17.17",
"@types/node": "20.2.1",
"source-map-support": "^0.5.21",
"ts-loader": "^9.4.2",
"ts-node": "^10.9.1",
"tsconfig-paths": "4.2.0"
}
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
},
"license": "MIT",
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-typescript": "^11.1.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint": "^8.38.0",
"@rollup/plugin-typescript": "^11.1.1",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.1",
"prettier": "^2.8.7",
"rollup": "^3.20.2",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"rollup": "^3.22.0",
"typescript": "^5.0.4"
},
"dependencies": {
"tslib": "^2.5.0"
"tslib": "^2.5.2"
}
}
4 changes: 2 additions & 2 deletions packages/passport-google-oauth-token/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passport-google-oauth-token",
"version": "1.0.6",
"version": "1.0.7",
"description": "Google access token authentication strategy for Passport",
"author": "Alpha",
"repository": {
Expand Down Expand Up @@ -42,6 +42,6 @@
"@types/oauth": "^0.9.1",
"@types/passport-oauth2": "^1.4.12",
"oauth": "^0.10.0",
"vitest": "^0.29.8"
"vitest": "^0.31.1"
}
}
17 changes: 16 additions & 1 deletion packages/passport-google-oauth-token/src/Strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,26 @@ export default class GoogleOauthTokenStrategy extends OAuth2Strategy {
});
}

protected _lookupAuthorization(req: Request): string {
if (!req.headers?.authorization) {
return '';
}

const matches = req.headers.authorization.match(/(\S+)\s+(\S+)/);

if (matches?.[1].toLowerCase() !== 'bearer') {
return '';
}

return matches?.[2] || '';
}

protected _lookup(req: Request, field: string): string {
return (
(req.body && req.body[field]) ||
(req.query && req.query[field]) ||
(req.headers && req.headers[field])
(req.headers && req.headers[field]) ||
this._lookupAuthorization(req)
);
}

Expand Down
Loading

0 comments on commit e797f63

Please sign in to comment.