refactoring
This commit is contained in:
@@ -3,6 +3,7 @@ import { ExecutionContext, Injectable } from '@nestjs/common';
|
|||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
import { AuthGuard as PassportAuthGuard } from '@nestjs/passport';
|
import { AuthGuard as PassportAuthGuard } from '@nestjs/passport';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
import { IS_PUBLIC_KEY } from './public.decorator';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthGuard extends PassportAuthGuard('azure-ad') implements CanActivate {
|
export class AuthGuard extends PassportAuthGuard('azure-ad') implements CanActivate {
|
||||||
@@ -12,7 +13,7 @@ export class AuthGuard extends PassportAuthGuard('azure-ad') implements CanActiv
|
|||||||
|
|
||||||
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
|
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
|
||||||
const isPublic = this.reflector.get<boolean>(
|
const isPublic = this.reflector.get<boolean>(
|
||||||
'isPublic',
|
IS_PUBLIC_KEY,
|
||||||
context.getHandler()
|
context.getHandler()
|
||||||
);
|
);
|
||||||
const req = context.switchToHttp().getRequest();
|
const req = context.switchToHttp().getRequest();
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { Inject, Injectable } from "@nestjs/common";
|
import { Inject, Injectable } from "@nestjs/common";
|
||||||
import { PassportStrategy } from "@nestjs/passport";
|
import { PassportStrategy } from "@nestjs/passport";
|
||||||
import { BearerStrategy } from 'passport-azure-ad';
|
|
||||||
import { AuthModuleOptions } from './auth.interface'
|
import { AuthModuleOptions } from './auth.interface'
|
||||||
import { MODULE_OPTIONS_TOKEN } from "./auth.module-definition";
|
import { MODULE_OPTIONS_TOKEN } from "./auth.module-definition";
|
||||||
|
import { BearerStrategy } from 'passport-azure-ad'
|
||||||
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||||
|
import * as jwksRsa from 'jwks-rsa';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AzureAdStrategy extends PassportStrategy(
|
export class AzureAdStrategy extends PassportStrategy(
|
||||||
@@ -24,3 +26,26 @@ export class AzureAdStrategy extends PassportStrategy(
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Injectable()
|
||||||
|
// export class AzureAdStrategy extends PassportStrategy(Strategy, 'azure-ad') {
|
||||||
|
// constructor(@Inject(MODULE_OPTIONS_TOKEN) authModuleOptions: AuthModuleOptions) {
|
||||||
|
// super({
|
||||||
|
// jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||||
|
// audience: `api://${authModuleOptions.clientId}`,
|
||||||
|
// issuer: `https://sts.windows.net/${authModuleOptions.tenantId}`,
|
||||||
|
// algorithms: ['RS256'],
|
||||||
|
// ignoreExpiration: true,
|
||||||
|
// secretOrKeyProvider: jwksRsa.passportJwtSecret({
|
||||||
|
// cache: true,
|
||||||
|
// rateLimit: true,
|
||||||
|
// jwksRequestsPerMinute: 5,
|
||||||
|
// jwksUri: `https://login.microsoftonline.com/${authModuleOptions.tenantId}`
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
|
// validate(payload: any) {
|
||||||
|
// return payload;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
import { SetMetadata } from "@nestjs/common";
|
import { SetMetadata } from "@nestjs/common";
|
||||||
|
|
||||||
export const Public = () => SetMetadata('isPublic', true);
|
export const IS_PUBLIC_KEY = 'isPublic'
|
||||||
|
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
|
||||||
|
|||||||
30
package-lock.json
generated
30
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@noahspan/noahspan-modules",
|
"name": "@noahspan/noahspan-modules",
|
||||||
"version": "0.5.2",
|
"version": "0.6.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@noahspan/noahspan-modules",
|
"name": "@noahspan/noahspan-modules",
|
||||||
"version": "0.5.2",
|
"version": "0.6.1",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@azure/app-configuration": "^1.6.0",
|
"@azure/app-configuration": "^1.6.0",
|
||||||
@@ -22,7 +22,9 @@
|
|||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
"express-jwt": "^8.5.1",
|
"express-jwt": "^8.5.1",
|
||||||
"jwks-rsa": "^3.1.0",
|
"jwks-rsa": "^3.1.0",
|
||||||
|
"passport": "^0.7.0",
|
||||||
"passport-azure-ad": "^4.3.5",
|
"passport-azure-ad": "^4.3.5",
|
||||||
|
"passport-jwt": "^4.0.1",
|
||||||
"reflect-metadata": "^0.2.0",
|
"reflect-metadata": "^0.2.0",
|
||||||
"rxjs": "^7.8.1"
|
"rxjs": "^7.8.1"
|
||||||
},
|
},
|
||||||
@@ -3373,9 +3375,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/async": {
|
"node_modules/async": {
|
||||||
"version": "3.2.5",
|
"version": "3.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz",
|
"resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz",
|
||||||
"integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg=="
|
"integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA=="
|
||||||
},
|
},
|
||||||
"node_modules/asynckit": {
|
"node_modules/asynckit": {
|
||||||
"version": "0.4.0",
|
"version": "0.4.0",
|
||||||
@@ -7410,9 +7412,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/nan": {
|
"node_modules/nan": {
|
||||||
"version": "2.19.0",
|
"version": "2.22.0",
|
||||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.19.0.tgz",
|
"resolved": "https://registry.npmjs.org/nan/-/nan-2.22.0.tgz",
|
||||||
"integrity": "sha512-nO1xXxfh/RWNxfd/XPfbIfFk5vgLsAxUR9y5O0cHMJu/AW9U95JLXqthYHjEp+8gQ5p96K9jUp8nbVOxCdRbtw==",
|
"integrity": "sha512-nbajikzWTMwsW+eSsNm3QwlOs7het9gGJU5dDZzRTQGk03vyBOauxgI4VakDzE0PtsGTmXPsXTbbjVhRwR5mpw==",
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"node_modules/natural-compare": {
|
"node_modules/natural-compare": {
|
||||||
@@ -7798,7 +7800,6 @@
|
|||||||
"version": "0.7.0",
|
"version": "0.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz",
|
||||||
"integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==",
|
"integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"passport-strategy": "1.x.x",
|
"passport-strategy": "1.x.x",
|
||||||
"pause": "0.0.1",
|
"pause": "0.0.1",
|
||||||
@@ -7816,7 +7817,7 @@
|
|||||||
"version": "4.3.5",
|
"version": "4.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/passport-azure-ad/-/passport-azure-ad-4.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/passport-azure-ad/-/passport-azure-ad-4.3.5.tgz",
|
||||||
"integrity": "sha512-LBpXEght7hCMuMNFK4oegdN0uPBa3lpDMy71zQoB0zPg1RrGwdzpjwTiN1WzN0hY77fLyjz9tBr3TGAxnSgtEg==",
|
"integrity": "sha512-LBpXEght7hCMuMNFK4oegdN0uPBa3lpDMy71zQoB0zPg1RrGwdzpjwTiN1WzN0hY77fLyjz9tBr3TGAxnSgtEg==",
|
||||||
"deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.",
|
"deprecated": "This package is deprecated and no longer supported. For more please visit https://github.com/AzureAD/passport-azure-ad?tab=readme-ov-file#node-js-validation-replacement-for-passportjs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^3.2.3",
|
"async": "^3.2.3",
|
||||||
"base64url": "^3.0.0",
|
"base64url": "^3.0.0",
|
||||||
@@ -7874,6 +7875,15 @@
|
|||||||
"url": "https://github.com/sponsors/jaredhanson"
|
"url": "https://github.com/sponsors/jaredhanson"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/passport-jwt": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/passport-jwt/-/passport-jwt-4.0.1.tgz",
|
||||||
|
"integrity": "sha512-UCKMDYhNuGOBE9/9Ycuoyh7vP6jpeTp/+sfMJl7nLff/t6dps+iaeE0hhNkKN8/HZHcJ7lCdOyDxHdDoxoSvdQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"jsonwebtoken": "^9.0.0",
|
||||||
|
"passport-strategy": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/passport-strategy": {
|
"node_modules/passport-strategy": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@noahspan/noahspan-modules",
|
"name": "@noahspan/noahspan-modules",
|
||||||
"version": "0.5.3",
|
"version": "0.6.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
@@ -37,7 +37,9 @@
|
|||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
"express-jwt": "^8.5.1",
|
"express-jwt": "^8.5.1",
|
||||||
"jwks-rsa": "^3.1.0",
|
"jwks-rsa": "^3.1.0",
|
||||||
|
"passport": "^0.7.0",
|
||||||
"passport-azure-ad": "^4.3.5",
|
"passport-azure-ad": "^4.3.5",
|
||||||
|
"passport-jwt": "^4.0.1",
|
||||||
"reflect-metadata": "^0.2.0",
|
"reflect-metadata": "^0.2.0",
|
||||||
"rxjs": "^7.8.1"
|
"rxjs": "^7.8.1"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user