Feat add iam auth
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
type AppJwtPayload,
|
||||
type AuthenticatedCustomer,
|
||||
} from './app-principal';
|
||||
import { AppSessionService } from '../sessions/app-session.service';
|
||||
|
||||
export {
|
||||
CUSTOMER_TOKEN_TYPE,
|
||||
@@ -41,7 +42,10 @@ export type CustomerJwtPayload = AppJwtPayload;
|
||||
*/
|
||||
@Injectable()
|
||||
export class CustomerJwtStrategy extends PassportStrategy(Strategy, 'customer-jwt') {
|
||||
constructor(private readonly prisma: PrismaService) {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly sessions: AppSessionService,
|
||||
) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
@@ -50,6 +54,12 @@ export class CustomerJwtStrategy extends PassportStrategy(Strategy, 'customer-jw
|
||||
}
|
||||
|
||||
async validate(payload: AppJwtPayload): Promise<AuthenticatedCustomer> {
|
||||
// نشست باطلشده (خروج سراسری از IdP یا ابطال محلی). در حالت خاموشِ ردیابی،
|
||||
// بدون هیچ کوئری true برمیگردد ⇒ هزینه و رفتار دقیقاً مثل قبل.
|
||||
if (!(await this.sessions.isActive(payload?.jti))) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
||||
if (payload?.typ === EXPERT_TOKEN_TYPE) {
|
||||
return this.validateExpert(payload);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user