frontend: streamline secret handling in guards and room service
This commit is contained in:
parent
e926dc2de7
commit
25f3d9f887
@ -10,14 +10,14 @@ export const extractRoomQueryParamsGuard: CanActivateFn = (route: ActivatedRoute
|
|||||||
const participantService = inject(ParticipantService);
|
const participantService = inject(ParticipantService);
|
||||||
const sessionStorageService = inject(SessionStorageService);
|
const sessionStorageService = inject(SessionStorageService);
|
||||||
|
|
||||||
const { roomId, participantName, secret, leaveRedirectUrl, showOnlyRecordings } = extractParams(route);
|
const { roomId, secret: querySecret, participantName, leaveRedirectUrl, showOnlyRecordings } = extractParams(route);
|
||||||
const storedSecret = sessionStorageService.getRoomSecret(roomId);
|
const secret = querySecret || sessionStorageService.getRoomSecret(roomId);
|
||||||
|
|
||||||
if (isValidUrl(leaveRedirectUrl)) {
|
if (isValidUrl(leaveRedirectUrl)) {
|
||||||
navigationService.setLeaveRedirectUrl(leaveRedirectUrl);
|
navigationService.setLeaveRedirectUrl(leaveRedirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!secret && !storedSecret) {
|
if (!secret) {
|
||||||
// If no secret is provided, redirect to the error page
|
// If no secret is provided, redirect to the error page
|
||||||
return navigationService.redirectToErrorPage(ErrorReason.MISSING_ROOM_SECRET);
|
return navigationService.redirectToErrorPage(ErrorReason.MISSING_ROOM_SECRET);
|
||||||
}
|
}
|
||||||
@ -57,11 +57,11 @@ export const extractRecordingQueryParamsGuard: CanActivateFn = (route: Activated
|
|||||||
};
|
};
|
||||||
|
|
||||||
const extractParams = ({ params, queryParams }: ActivatedRouteSnapshot) => ({
|
const extractParams = ({ params, queryParams }: ActivatedRouteSnapshot) => ({
|
||||||
roomId: params['room-id'],
|
roomId: params['room-id'] as string,
|
||||||
participantName: queryParams[WebComponentProperty.PARTICIPANT_NAME],
|
secret: queryParams['secret'] as string,
|
||||||
secret: queryParams['secret'],
|
participantName: queryParams[WebComponentProperty.PARTICIPANT_NAME] as string,
|
||||||
leaveRedirectUrl: queryParams[WebComponentProperty.LEAVE_REDIRECT_URL],
|
leaveRedirectUrl: queryParams[WebComponentProperty.LEAVE_REDIRECT_URL] as string,
|
||||||
showOnlyRecordings: queryParams[WebComponentProperty.SHOW_ONLY_RECORDINGS] || 'false'
|
showOnlyRecordings: (queryParams[WebComponentProperty.SHOW_ONLY_RECORDINGS] as string) || 'false'
|
||||||
});
|
});
|
||||||
|
|
||||||
const isValidUrl = (url: string) => {
|
const isValidUrl = (url: string) => {
|
||||||
|
|||||||
@ -1,18 +1,16 @@
|
|||||||
import { inject } from '@angular/core';
|
import { inject } from '@angular/core';
|
||||||
import { CanActivateFn, NavigationEnd, Router } from '@angular/router';
|
import { CanActivateFn, NavigationEnd, Router } from '@angular/router';
|
||||||
import { NavigationService, RoomService, SessionStorageService } from '@lib/services';
|
import { NavigationService } from '@lib/services';
|
||||||
import { filter, take } from 'rxjs';
|
import { filter, take } from 'rxjs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guard that intercepts navigation to remove the 'secret' query parameter from the URL
|
* Guard that intercepts navigation to remove the 'secret' query parameter from the URL
|
||||||
* when a participant joins a room. The secret is stored in session storage for the current room,
|
* that determine the role of a participant when joining a room or accessing its recordings,
|
||||||
* and the URL is updated without the 'secret' parameter to enhance security.
|
* in order to enhance security.
|
||||||
*/
|
*/
|
||||||
export const removeRoomSecretGuard: CanActivateFn = (route, _state) => {
|
export const removeRoomSecretGuard: CanActivateFn = (route, _state) => {
|
||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
const roomService = inject(RoomService);
|
|
||||||
const navigationService = inject(NavigationService);
|
const navigationService = inject(NavigationService);
|
||||||
const sessionStorageService = inject(SessionStorageService);
|
|
||||||
|
|
||||||
router.events
|
router.events
|
||||||
.pipe(
|
.pipe(
|
||||||
@ -20,11 +18,6 @@ export const removeRoomSecretGuard: CanActivateFn = (route, _state) => {
|
|||||||
take(1)
|
take(1)
|
||||||
)
|
)
|
||||||
.subscribe(async () => {
|
.subscribe(async () => {
|
||||||
const roomId = roomService.getRoomId();
|
|
||||||
const secret = roomService.getRoomSecret();
|
|
||||||
|
|
||||||
// Store the secret in session storage for the current room and remove it from the URL
|
|
||||||
sessionStorageService.setRoomSecret(roomId, secret);
|
|
||||||
await navigationService.removeQueryParamFromUrl(route.queryParams, 'secret');
|
await navigationService.removeQueryParamFromUrl(route.queryParams, 'secret');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -39,9 +39,9 @@ export const baseRoutes: Routes = [
|
|||||||
canActivate: [
|
canActivate: [
|
||||||
runGuardsSerially(
|
runGuardsSerially(
|
||||||
extractRoomQueryParamsGuard,
|
extractRoomQueryParamsGuard,
|
||||||
|
removeRoomSecretGuard,
|
||||||
checkParticipantRoleAndAuthGuard,
|
checkParticipantRoleAndAuthGuard,
|
||||||
validateRoomAccessGuard,
|
validateRoomAccessGuard
|
||||||
removeRoomSecretGuard
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -51,9 +51,9 @@ export const baseRoutes: Routes = [
|
|||||||
canActivate: [
|
canActivate: [
|
||||||
runGuardsSerially(
|
runGuardsSerially(
|
||||||
extractRecordingQueryParamsGuard,
|
extractRecordingQueryParamsGuard,
|
||||||
|
removeRoomSecretGuard,
|
||||||
checkParticipantRoleAndAuthGuard,
|
checkParticipantRoleAndAuthGuard,
|
||||||
validateRecordingAccessGuard,
|
validateRecordingAccessGuard
|
||||||
removeRoomSecretGuard
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -39,14 +39,9 @@ export class RoomService {
|
|||||||
return this.roomId;
|
return this.roomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
setRoomSecret(secret?: string) {
|
setRoomSecret(secret: string) {
|
||||||
// If no secret is provided, check session storage for the current room's secret
|
|
||||||
if (!secret) {
|
|
||||||
const storedSecret = this.sessionStorageService.getRoomSecret(this.roomId);
|
|
||||||
this.roomSecret = storedSecret || '';
|
|
||||||
} else {
|
|
||||||
this.roomSecret = secret;
|
this.roomSecret = secret;
|
||||||
}
|
this.sessionStorageService.setRoomSecret(this.roomId, secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRoomSecret(): string {
|
getRoomSecret(): string {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user