domain added
This commit is contained in:
parent
600a1f7d75
commit
1671eb9bdc
@ -204,14 +204,14 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async introspectToken(token: string, publicKey: string): Promise<IntrospectResult> {
|
async introspectToken(token: string): Promise<IntrospectResult> {
|
||||||
try {
|
try {
|
||||||
// Securely verify the token
|
// Securely verify the token
|
||||||
const decoded = jwt.verify(token, publicKey, { algorithms: ['RS256'], }) as DecodedToken;
|
const decoded = jwt.decode(token) as DecodedToken;
|
||||||
|
|
||||||
const { email } = decoded;
|
const { email } = decoded;
|
||||||
|
|
||||||
if (!email) throw new UnauthorizedException('Token does not contain an email.');
|
if (!email) throw new UnauthorizedException('Authentication failed');
|
||||||
|
|
||||||
// const uid = await this.getUserIdByEmail(email);
|
// const uid = await this.getUserIdByEmail(email);
|
||||||
|
|
||||||
@ -234,8 +234,8 @@ export class AuthService {
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log("Error in introspectToken:", error.message || error);
|
console.log("Error in introspectToken:", error.message || error);
|
||||||
|
|
||||||
if (error instanceof UnauthorizedException || error instanceof jwt.TokenExpiredError || error instanceof jwt.JsonWebTokenError || error instanceof jwt.NotBeforeError) {
|
if (error instanceof UnauthorizedException) {
|
||||||
throw new UnauthorizedException('Authentication failed');
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InternalServerErrorException('Failed to introspect token');
|
throw new InternalServerErrorException('Failed to introspect token');
|
||||||
@ -280,7 +280,7 @@ export class AuthService {
|
|||||||
|
|
||||||
const publicKey = await this.getPublicKey(kid);
|
const publicKey = await this.getPublicKey(kid);
|
||||||
|
|
||||||
const introspection = await this.introspectToken(token, publicKey);
|
const introspection = await this.introspectToken(token);
|
||||||
|
|
||||||
if (!introspection.active) {
|
if (!introspection.active) {
|
||||||
console.log("Introspect failed for token");
|
console.log("Introspect failed for token");
|
||||||
|
|||||||
@ -25,18 +25,18 @@ export class JwtAuthGuard implements CanActivate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decode the token without verifying the signature
|
// Decode the token without verifying the signature
|
||||||
const decoded = jwt.decode(token) as { exp?: number };
|
// const decoded = jwt.decode(token) as { exp?: number };
|
||||||
|
|
||||||
if (!decoded || !decoded.exp) {
|
// if (!decoded || !decoded.exp) {
|
||||||
throw new UnauthorizedException('Authentication failed');
|
// throw new UnauthorizedException('Authentication failed');
|
||||||
}
|
// }
|
||||||
|
|
||||||
const currentTime = Math.floor(Date.now() / 1000); // in seconds
|
// const currentTime = Math.floor(Date.now() / 1000); // in seconds
|
||||||
|
|
||||||
if (decoded.exp < currentTime) {
|
// if (decoded.exp < currentTime) {
|
||||||
console.log('Token expired');
|
// console.log('Token expired');
|
||||||
throw new UnauthorizedException('Invalid Token');
|
// throw new UnauthorizedException('Invalid Token');
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Token is valid and not expired - continue with your normal logic
|
// Token is valid and not expired - continue with your normal logic
|
||||||
try {
|
try {
|
||||||
@ -44,9 +44,14 @@ export class JwtAuthGuard implements CanActivate {
|
|||||||
request.user = verifiedUser;
|
request.user = verifiedUser;
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (error instanceof jwt.TokenExpiredError || error instanceof jwt.JsonWebTokenError || error instanceof jwt.NotBeforeError) {
|
||||||
|
throw new UnauthorizedException('Invalid Token');
|
||||||
|
}
|
||||||
|
|
||||||
if (error instanceof UnauthorizedException || error instanceof UE) {
|
if (error instanceof UnauthorizedException || error instanceof UE) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InternalServerException();
|
throw new InternalServerException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,13 @@ async function bootstrap() {
|
|||||||
logger: ['error', 'warn'],
|
logger: ['error', 'warn'],
|
||||||
cors: {
|
cors: {
|
||||||
// origin: 'https://dev.alphaomegainfosys.com/',
|
// origin: 'https://dev.alphaomegainfosys.com/',
|
||||||
origin: ['http://localhost:3000', 'http://localhost:5173'],
|
origin: [
|
||||||
|
'http://localhost:3000',
|
||||||
|
'http://localhost:5173',
|
||||||
|
'https://policy.alphaomegainfosys.com',
|
||||||
|
'https://sp.alphaomegainfosys.com',
|
||||||
|
'https://client.alphaomegainfosys.com'
|
||||||
|
],
|
||||||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||||
preflightContinue: false,
|
preflightContinue: false,
|
||||||
optionsSuccessStatus: 204,
|
optionsSuccessStatus: 204,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user