refactor(center): introspect relies on api key auth instead of shared secret
This commit is contained in:
@@ -37,10 +37,7 @@ export class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('introspect')
|
@Post('introspect')
|
||||||
introspect(
|
introspect(@Body() body: { token?: string; guildNodeId?: string }) {
|
||||||
@Body() body: { token?: string; guildNodeId?: string },
|
return this.authService.introspectGuildToken(body?.token ?? '', body?.guildNodeId ?? '');
|
||||||
@Headers('x-center-shared-secret') sharedSecret?: string,
|
|
||||||
) {
|
|
||||||
return this.authService.introspectGuildToken(body?.token ?? '', body?.guildNodeId ?? '', sharedSecret);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
ConflictException,
|
ConflictException,
|
||||||
Injectable,
|
Injectable,
|
||||||
ForbiddenException,
|
|
||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
@@ -175,12 +174,7 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async introspectGuildToken(token: string, guildNodeId: string, sharedSecret?: string) {
|
async introspectGuildToken(token: string, guildNodeId: string) {
|
||||||
const expectedSecret = process.env.CENTER_SHARED_SECRET as string;
|
|
||||||
if (!sharedSecret || sharedSecret !== expectedSecret) {
|
|
||||||
throw new ForbiddenException('invalid shared secret');
|
|
||||||
}
|
|
||||||
|
|
||||||
let payload: jwt.JwtPayload;
|
let payload: jwt.JwtPayload;
|
||||||
try {
|
try {
|
||||||
payload = jwt.verify(token, process.env.JWT_ACCESS_SECRET as string) as jwt.JwtPayload;
|
payload = jwt.verify(token, process.env.JWT_ACCESS_SECRET as string) as jwt.JwtPayload;
|
||||||
|
|||||||
Reference in New Issue
Block a user