frontend: Add secret handling to context service and guards for improved room access validation
This commit is contained in:
parent
c72315d90a
commit
314b9fae21
@ -4,7 +4,7 @@ import { ContextService } from '../services';
|
|||||||
|
|
||||||
export const extractQueryParamsGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => {
|
export const extractQueryParamsGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => {
|
||||||
const contextService = inject(ContextService);
|
const contextService = inject(ContextService);
|
||||||
const { roomName, participantName, leaveRedirectUrl } = extractParams(route);
|
const { roomName, participantName, secret, leaveRedirectUrl } = extractParams(route);
|
||||||
|
|
||||||
if (isValidUrl(leaveRedirectUrl)) {
|
if (isValidUrl(leaveRedirectUrl)) {
|
||||||
contextService.setLeaveRedirectUrl(leaveRedirectUrl);
|
contextService.setLeaveRedirectUrl(leaveRedirectUrl);
|
||||||
@ -12,6 +12,7 @@ export const extractQueryParamsGuard: CanActivateFn = (route: ActivatedRouteSnap
|
|||||||
|
|
||||||
contextService.setRoomName(roomName);
|
contextService.setRoomName(roomName);
|
||||||
contextService.setParticipantName(participantName);
|
contextService.setParticipantName(participantName);
|
||||||
|
contextService.setSecret(secret);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { ContextService, HttpService, SessionStorageService } from '../services'
|
|||||||
* Guard to validate the access to a room.
|
* Guard to validate the access to a room.
|
||||||
*/
|
*/
|
||||||
export const validateRoomAccessGuard: CanActivateFn = async (
|
export const validateRoomAccessGuard: CanActivateFn = async (
|
||||||
route: ActivatedRouteSnapshot,
|
_route: ActivatedRouteSnapshot,
|
||||||
_state: RouterStateSnapshot
|
_state: RouterStateSnapshot
|
||||||
) => {
|
) => {
|
||||||
const httpService = inject(HttpService);
|
const httpService = inject(HttpService);
|
||||||
@ -14,7 +14,9 @@ export const validateRoomAccessGuard: CanActivateFn = async (
|
|||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
const sessionStorageService = inject(SessionStorageService);
|
const sessionStorageService = inject(SessionStorageService);
|
||||||
|
|
||||||
const { roomName, participantName, secret } = extractParams(route);
|
const roomName = contextService.getRoomName();
|
||||||
|
const participantName = contextService.getParticipantName();
|
||||||
|
const secret = contextService.getSecret();
|
||||||
const storageSecret = sessionStorageService.getModeratorSecret(roomName);
|
const storageSecret = sessionStorageService.getModeratorSecret(roomName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -47,12 +49,6 @@ export const validateRoomAccessGuard: CanActivateFn = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractParams = (route: ActivatedRouteSnapshot) => ({
|
|
||||||
roomName: route.params['room-name'],
|
|
||||||
participantName: route.queryParams['participant-name'],
|
|
||||||
secret: route.queryParams['secret']
|
|
||||||
});
|
|
||||||
|
|
||||||
const redirectToUnauthorized = async (router: Router, reason: string): Promise<boolean> => {
|
const redirectToUnauthorized = async (router: Router, reason: string): Promise<boolean> => {
|
||||||
await router.navigate(['unauthorized'], { queryParams: { reason } });
|
await router.navigate(['unauthorized'], { queryParams: { reason } });
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { OpenViduMeetPermissions, ParticipantRole } from 'projects/shared-meet-c
|
|||||||
export interface ContextData {
|
export interface ContextData {
|
||||||
roomName: string;
|
roomName: string;
|
||||||
participantName: string;
|
participantName: string;
|
||||||
|
secret: string;
|
||||||
token: string;
|
token: string;
|
||||||
participantRole: ParticipantRole;
|
participantRole: ParticipantRole;
|
||||||
participantPermissions: OpenViduMeetPermissions;
|
participantPermissions: OpenViduMeetPermissions;
|
||||||
|
|||||||
@ -14,6 +14,7 @@ export class ContextService {
|
|||||||
private context: ContextData = {
|
private context: ContextData = {
|
||||||
roomName: '',
|
roomName: '',
|
||||||
participantName: '',
|
participantName: '',
|
||||||
|
secret: '',
|
||||||
token: '',
|
token: '',
|
||||||
participantRole: ParticipantRole.PUBLISHER,
|
participantRole: ParticipantRole.PUBLISHER,
|
||||||
participantPermissions: {
|
participantPermissions: {
|
||||||
@ -118,6 +119,14 @@ export class ContextService {
|
|||||||
this.context.participantName = participantName;
|
this.context.participantName = participantName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSecret(): string {
|
||||||
|
return this.context.secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSecret(secret: string): void {
|
||||||
|
this.context.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
canRecord(): boolean {
|
canRecord(): boolean {
|
||||||
return this.context.participantPermissions.canRecord;
|
return this.context.participantPermissions.canRecord;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user