generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ORV2-2532 Proceed to Route Handler if one of the guard validates…
… successfully (#1460)
- Loading branch information
Showing
4 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { Observable } from 'rxjs'; | ||
import { JwtAuthGuard } from './auth.guard'; | ||
import { JwtServiceAccountAuthGuard } from './jwt-sa-auth.guard'; | ||
import { Reflector } from '@nestjs/core'; | ||
|
||
@Injectable() | ||
export class JwtOneOfAuthGuard implements CanActivate { | ||
constructor(private reflector: Reflector) {} | ||
canActivate( | ||
context: ExecutionContext, | ||
): boolean | Promise<boolean> | Observable<boolean> { | ||
const jwtAuthGuard = new JwtAuthGuard(this.reflector); | ||
const jwtServiceAccountAuthGuard = new JwtServiceAccountAuthGuard( | ||
this.reflector, | ||
); | ||
|
||
try { | ||
return jwtAuthGuard.canActivate(context); // Attempt to activate the jwtAuthGuard | ||
} catch (error) { | ||
// If the jwtAuthGuard fails, attempt to activate the jwtServiceAccountAuthGuard | ||
return jwtServiceAccountAuthGuard.canActivate(context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { Observable } from 'rxjs'; | ||
import { JwtAuthGuard } from './auth.guard'; | ||
import { JwtServiceAccountAuthGuard } from './jwt-sa-auth.guard'; | ||
import { Reflector } from '@nestjs/core'; | ||
|
||
@Injectable() | ||
export class JwtOneOfAuthGuard implements CanActivate { | ||
constructor(private reflector: Reflector) {} | ||
canActivate( | ||
context: ExecutionContext, | ||
): boolean | Promise<boolean> | Observable<boolean> { | ||
const jwtAuthGuard = new JwtAuthGuard(this.reflector); | ||
const jwtServiceAccountAuthGuard = new JwtServiceAccountAuthGuard( | ||
this.reflector, | ||
); | ||
|
||
try { | ||
return jwtAuthGuard.canActivate(context); // Attempt to activate the jwtAuthGuard | ||
} catch (error) { | ||
// If the jwtAuthGuard fails, attempt to activate the jwtServiceAccountAuthGuard | ||
return jwtServiceAccountAuthGuard.canActivate(context); | ||
} | ||
} | ||
} |