#![cfg(not(target_arch = "wasm32"))]
use std::sync::Arc;
#[derive(Debug, Clone, Default)]
pub struct ScopeClassification {
pub session_kind: Option<&'static str>,
pub grant_id: Option<String>,
pub scope: Option<String>,
}
pub trait ScopeClassifier: Send + Sync + 'static {
fn classify_scopes(&self, scopes: &[String]) -> ScopeClassification;
}
#[derive(Debug, Clone, Default)]
pub struct LegacyScopeClassifier;
impl ScopeClassifier for LegacyScopeClassifier {
fn classify_scopes(&self, scopes: &[String]) -> ScopeClassification {
for scope in scopes {
if let Some(grant_id) = scope.strip_prefix("drive-grant:") {
return ScopeClassification {
session_kind: Some("drive-grant-guest"),
grant_id: Some(grant_id.to_string()),
scope: Some(scope.clone()),
};
}
}
for scope in scopes {
if scope == "user-device" {
return ScopeClassification {
session_kind: Some("app-user-device"),
grant_id: None,
scope: Some(scope.clone()),
};
}
}
ScopeClassification::default()
}
}
pub fn default_scope_classifier() -> Arc<dyn ScopeClassifier> {
Arc::new(LegacyScopeClassifier::default())
}