Enhanced GitHub token validator with scope detection
(token: &str, client: &Client)
| 328 | |
| 329 | /// Enhanced GitHub token validator with scope detection |
| 330 | pub async fn validate_github_token_enhanced(token: &str, client: &Client) -> (bool, String, Vec<String>) { |
| 331 | let url = "https://api.github.com/user"; |
| 332 | |
| 333 | match client |
| 334 | .get(url) |
| 335 | .bearer_auth(token) |
| 336 | .header("User-Agent", "EnumRust-Security-Scanner") |
| 337 | .timeout(Duration::from_secs(10)) |
| 338 | .send() |
| 339 | .await |
| 340 | { |
| 341 | Ok(response) => { |
| 342 | let status = response.status(); |
| 343 | let scopes = response |
| 344 | .headers() |
| 345 | .get("x-oauth-scopes") |
| 346 | .and_then(|v| v.to_str().ok()) |
| 347 | .unwrap_or("") |
| 348 | .split(',') |
| 349 | .map(|s| s.trim().to_string()) |
| 350 | .filter(|s| !s.is_empty()) |
| 351 | .collect(); |
| 352 | |
| 353 | if status.is_success() { |
| 354 | (true, "VALID_ACTIVE".to_string(), scopes) |
| 355 | } else if status.as_u16() == 401 { |
| 356 | (false, "INVALID_EXPIRED".to_string(), vec![]) |
| 357 | } else { |
| 358 | (false, "ERROR_TESTING".to_string(), vec![]) |
| 359 | } |
| 360 | } |
| 361 | Err(_) => (false, "ERROR_TESTING".to_string(), vec![]), |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /// Enhanced Vercel token validator |
| 366 | pub async fn validate_vercel_token_enhanced(token: &str, client: &Client) -> (bool, String, Vec<String>) { |
no outgoing calls
no test coverage detected