Line data Source code
1 : use utils::auth::{AuthError, Claims, Scope};
2 : use uuid::Uuid;
3 :
4 0 : pub fn check_permission(claims: &Claims, required_scope: Scope) -> Result<(), AuthError> {
5 0 : if claims.scope != required_scope {
6 0 : return Err(AuthError("Scope mismatch. Permission denied".into()));
7 0 : }
8 :
9 0 : Ok(())
10 0 : }
11 :
12 : #[allow(dead_code)]
13 0 : pub fn check_endpoint_permission(claims: &Claims, endpoint_id: Uuid) -> Result<(), AuthError> {
14 0 : if claims.scope != Scope::TenantEndpoint {
15 0 : return Err(AuthError("Scope mismatch. Permission denied".into()));
16 0 : }
17 0 : if claims.endpoint_id != Some(endpoint_id) {
18 0 : return Err(AuthError("Endpoint id mismatch. Permission denied".into()));
19 0 : }
20 0 : Ok(())
21 0 : }
|