Change log to logger
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { Injectable, UnauthorizedException, Logger } from '@nestjs/common';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
|
||||
@@ -49,33 +49,37 @@ export class KeycloakJwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
||||
});
|
||||
}
|
||||
|
||||
private readonly logger = new Logger(KeycloakJwtStrategy.name);
|
||||
|
||||
validate(payload: JwtPayload): JwtPayload {
|
||||
console.log('JWT Payload received:', JSON.stringify(payload, null, 2));
|
||||
this.logger.debug(
|
||||
`JWT Payload received: ${JSON.stringify(payload, null, 2)}`,
|
||||
);
|
||||
|
||||
// Log important JWT claims
|
||||
console.log('JWT Subject (sub):', payload.sub);
|
||||
console.log('JWT Issuer (iss):', payload.iss);
|
||||
console.log('JWT Audience (aud):', payload.aud);
|
||||
console.log(
|
||||
'JWT Expiration (exp):',
|
||||
new Date(payload.exp * 1000).toISOString(),
|
||||
this.logger.debug(`JWT Subject (sub): ${payload.sub}`);
|
||||
this.logger.debug(`JWT Issuer (iss): ${payload.iss}`);
|
||||
this.logger.debug(`JWT Audience (aud): ${JSON.stringify(payload.aud)}`);
|
||||
this.logger.debug(
|
||||
`JWT Expiration (exp): ${new Date(payload.exp * 1000).toISOString()}`,
|
||||
);
|
||||
console.log(
|
||||
'JWT Issued At (iat):',
|
||||
new Date(payload.iat * 1000).toISOString(),
|
||||
this.logger.debug(
|
||||
`JWT Issued At (iat): ${new Date(payload.iat * 1000).toISOString()}`,
|
||||
);
|
||||
|
||||
// Log user info
|
||||
console.log('User email:', payload.email);
|
||||
console.log('Username:', payload.preferred_username);
|
||||
this.logger.debug(`User email: ${payload.email}`);
|
||||
this.logger.debug(`Username: ${payload.preferred_username}`);
|
||||
|
||||
// Log roles
|
||||
console.log('Realm access roles:', payload.realm_access?.roles || []);
|
||||
this.logger.debug(
|
||||
`Realm access roles: ${JSON.stringify(payload.realm_access?.roles || [])}`,
|
||||
);
|
||||
|
||||
if (payload.resource_access) {
|
||||
console.log('Resource access:');
|
||||
this.logger.debug('Resource access:');
|
||||
Object.entries(payload.resource_access).forEach(([resource, data]) => {
|
||||
console.log(` ${resource}:`, data.roles || []);
|
||||
this.logger.debug(` ${resource}: ${JSON.stringify(data.roles || [])}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user