Organize device inventory by customer and restrict token access to its audience
This commit is contained in:
@@ -261,13 +261,26 @@ impl Auth {
|
||||
}
|
||||
p
|
||||
};
|
||||
if p.name.starts_with("local:")
|
||||
&& !self
|
||||
if p.name.starts_with("local:") {
|
||||
let home = self
|
||||
.local
|
||||
.as_ref()
|
||||
.is_some_and(|local| local.enabled(&p.name, p.tenant))
|
||||
{
|
||||
return Err(StatusCode::FORBIDDEN);
|
||||
.and_then(|local| local.home(&p.name))
|
||||
.ok_or(StatusCode::FORBIDDEN)?;
|
||||
let tenants: Vec<Uuid> = sqlx::query_scalar("SELECT local_customer_tenants($1,$2)")
|
||||
.bind(&p.name)
|
||||
.bind(home)
|
||||
.fetch_one(&state.pool)
|
||||
.await
|
||||
.map_err(|_| StatusCode::SERVICE_UNAVAILABLE)?;
|
||||
if !tenants.contains(&home) {
|
||||
return Err(StatusCode::FORBIDDEN);
|
||||
}
|
||||
p.tenant = selected.unwrap_or(home);
|
||||
if !tenants.contains(&p.tenant) {
|
||||
return Err(StatusCode::NOT_FOUND);
|
||||
}
|
||||
p.tenants = tenants;
|
||||
}
|
||||
if selected.is_some_and(|t| t != p.tenant) {
|
||||
return Err(StatusCode::NOT_FOUND);
|
||||
|
||||
Reference in New Issue
Block a user