Remove expired old token condition when refreshing participant token

This commit is contained in:
juancarmore 2025-08-13 20:23:48 +02:00
parent f5d874d06d
commit 26b1750377
7 changed files with 2 additions and 51 deletions

View File

@ -1,8 +0,0 @@
description: Conflict — Current token is still valid
content:
application/json:
schema:
$ref: '../../schemas/error.yaml'
example:
error: Participant Error
message: 'Participant token is still valid'

View File

@ -50,8 +50,6 @@
$ref: '../../components/responses/forbidden-error.yaml'
'404':
$ref: '../../components/responses/internal/error-room-participant-not-found.yaml'
'409':
$ref: '../../components/responses/internal/error-participant-token-still-valid.yaml'
'422':
$ref: '../../components/responses/validation-error.yaml'
'500':

View File

@ -5,7 +5,6 @@ import INTERNAL_CONFIG from '../config/internal-config.js';
import {
errorInvalidParticipantToken,
errorParticipantTokenNotPresent,
errorParticipantTokenStillValid,
handleError,
rejectRequestFromMeetError
} from '../models/error.model.js';
@ -57,29 +56,17 @@ export const generateParticipantToken = async (req: Request, res: Response) => {
export const refreshParticipantToken = async (req: Request, res: Response) => {
const logger = container.get(LoggerService);
// Check if there is a previous token and if it is expired
// Check if there is a previous token
const previousToken = req.cookies[INTERNAL_CONFIG.PARTICIPANT_TOKEN_COOKIE_NAME];
// If there is no previous token, we cannot refresh it
if (!previousToken) {
logger.verbose('No previous participant token found. Cannot refresh.');
const error = errorParticipantTokenNotPresent();
return rejectRequestFromMeetError(res, error);
}
const tokenService = container.get(TokenService);
// If the previous token is still valid, we do not need to refresh it
try {
await tokenService.verifyToken(previousToken);
logger.verbose('Previous participant token is valid. No need to refresh');
const error = errorParticipantTokenStillValid();
return rejectRequestFromMeetError(res, error);
} catch (error) {
// Previous token is expired, we can proceed to refresh it
}
// Extract roles from the previous token
const tokenService = container.get(TokenService);
const participantService = container.get(ParticipantService);
let currentRoles: { role: ParticipantRole; permissions: OpenViduMeetPermissions }[] = [];

View File

@ -230,10 +230,6 @@ export const errorParticipantAlreadyExists = (participantIdentity: string, roomI
);
};
export const errorParticipantTokenStillValid = (): OpenViduMeetError => {
return new OpenViduMeetError('Participant Error', 'Participant token is still valid', 409);
};
export const errorParticipantTokenNotPresent = (): OpenViduMeetError => {
return new OpenViduMeetError('Participant', 'No participant token provided', 400);
};

View File

@ -119,20 +119,6 @@ describe('Participant API Tests', () => {
);
expect(response.status).toBe(404);
});
it('should fail with 409 when participant token is still valid', async () => {
const newRoomData = await setupSingleRoom(true);
const response = await refreshParticipantToken(
{
roomId: newRoomData.room.roomId,
secret: newRoomData.moderatorSecret,
participantName
},
newRoomData.moderatorCookie
);
expect(response.status).toBe(409);
expect(response.body.message).toBe('Participant token is still valid');
});
});
describe('Refresh Participant Token Validation Tests', () => {

View File

@ -56,13 +56,6 @@ export const httpInterceptor: HttpInterceptorFn = (req: HttpRequest<unknown>, ne
}),
catchError((error: HttpErrorResponse) => {
if (error.url?.includes('/token/refresh')) {
if (error.status === 409) {
console.log('Participant token is still valid');
// This means that the unauthorized error was due to an expired access token
// Refresh the access token and try again
return refreshAccessToken(firstError);
}
console.error('Error refreshing participant token');
throw firstError;
}

View File

@ -77,7 +77,6 @@ export class ParticipantService {
livekit: decodedToken.video,
openvidu: openviduPermissions
};
console.warn('PARTICIPANT PERMISSIONS', this.permissions);
// Update feature configuration
this.featureConfService.setParticipantRole(this.role);