refactoring
This commit is contained in:
@@ -3,6 +3,7 @@ import { ExecutionContext, Injectable } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { AuthGuard as PassportAuthGuard } from '@nestjs/passport';
|
||||
import { Observable } from 'rxjs';
|
||||
import { IS_PUBLIC_KEY } from './public.decorator';
|
||||
|
||||
@Injectable()
|
||||
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> {
|
||||
const isPublic = this.reflector.get<boolean>(
|
||||
'isPublic',
|
||||
IS_PUBLIC_KEY,
|
||||
context.getHandler()
|
||||
);
|
||||
const req = context.switchToHttp().getRequest();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import { PassportStrategy } from "@nestjs/passport";
|
||||
import { BearerStrategy } from 'passport-azure-ad';
|
||||
import { AuthModuleOptions } from './auth.interface'
|
||||
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()
|
||||
export class AzureAdStrategy extends PassportStrategy(
|
||||
@@ -23,4 +25,27 @@ export class AzureAdStrategy extends PassportStrategy(
|
||||
async validate(data: any): Promise<any> {
|
||||
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";
|
||||
|
||||
export const Public = () => SetMetadata('isPublic', true);
|
||||
export const IS_PUBLIC_KEY = 'isPublic'
|
||||
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
|
||||
|
||||
Reference in New Issue
Block a user