Skip to content

Commit d3301cf

Browse files
committed
Clean up join authorization logic
1 parent 389cb8c commit d3301cf

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/lib.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -405,31 +405,28 @@ extern "C" fn hangup_media(handle: *mut PluginSession) {
405405
fn process_join(from: &Arc<Session>, room_id: RoomId, user_id: UserId, subscribe: Option<Subscription>, token: Option<String>) -> MessageResult {
406406
// todo: holy shit clean this function up somehow
407407
let config = STATE.config.get().unwrap();
408-
match &config.auth_key {
409-
Some(ref key) => {
410-
match token {
411-
Some(ref token) => {
412-
match ValidatedToken::from_str(token, key) {
413-
Ok(tok) => {
414-
janus_warn!("Processing validated join from {:p} to room ID {} with user ID {}. Join allowed: {}", from.handle, room_id, user_id, tok.join_hub);
415-
if !tok.join_hub {
416-
return Err(From::from("Rejecting join with no join_hub permission!"))
417-
}
418-
}
419-
Err(e) => {
420-
janus_warn!("Processing invalid join from {:p} to room ID {} with user ID {}. Error: {}", from.handle, room_id, user_id, e);
421-
return Err(From::from("Rejecting join with invalid token!"))
422-
}
423-
}
424-
},
425-
_ => {
426-
janus_warn!("Processing anonymous join from {:p} to room ID {} with user ID {}.", from.handle, room_id, user_id);
427-
return Err(From::from("Rejecting anonymous join!"))
408+
match (&config.auth_key, token) {
409+
(None, _) => {
410+
janus_verb!("No auth_key configured. Allowing join from {:p} to room {} as user {}.", from.handle, room_id, user_id);
411+
}
412+
(Some(_), None) => {
413+
janus_warn!("Rejecting anonymous join from {:p} to room {} as user {}.", from.handle, room_id, user_id);
414+
return Err(From::from("Rejecting anonymous join!"))
415+
}
416+
(Some(key), Some(ref token)) => {
417+
match ValidatedToken::from_str(token, key) {
418+
Ok(ref claims) if claims.join_hub => {
419+
janus_verb!("Allowing validated join from {:p} to room {} as user {}.", from.handle, room_id, user_id);
420+
}
421+
Ok(_) => {
422+
janus_warn!("Rejecting unauthorized join from {:p} to room {} as user {}.", from.handle, room_id, user_id);
423+
return Err(From::from("Rejecting join with no join_hub permission!"))
424+
}
425+
Err(e) => {
426+
janus_warn!("Rejecting invalid join from {:p} to room {} as user {}. Error: {}", from.handle, room_id, user_id, e);
427+
return Err(From::from("Rejecting join with invalid token!"))
428428
}
429429
}
430-
},
431-
_ => {
432-
janus_warn!("No auth_key configured. Allowing join from {:p} to room ID {} with user ID {}.", from.handle, room_id, user_id);
433430
}
434431
}
435432

0 commit comments

Comments
 (0)