Skip to main content

github_mcp/auth/
auth_strategy.rs

1// GitHub v3 REST API MCP server — generated by mcpify. Do not hand-edit.
2
3use std::collections::HashMap;
4
5use async_trait::async_trait;
6
7/// Fields vary by scheme (e.g. `authorization_header` for Basic/PAT/OAuth2,
8/// `consumer_key`/`private_key` for OAuth1, `api_key` for API-key auth) —
9/// kept as a flexible string map rather than a per-scheme type, since
10/// exactly one strategy is active per deployment (REQ-1.2.3) and callers
11/// already know which shape to expect from the strategy they're using.
12pub type Credentials = HashMap<String, String>;
13pub type AuthConfig = HashMap<String, String>;
14
15/// One implementation per auth scheme discovered in the OpenAPI spec
16/// (REQ-1.2.2). `refresh_token`'s default errors out, since not every
17/// scheme has a refresh flow (only OAuth2 does in practice) — overridden by
18/// the strategies that do.
19#[async_trait]
20pub trait AuthStrategy: Send + Sync {
21    async fn authenticate(&self, config: &AuthConfig) -> anyhow::Result<Credentials>;
22
23    async fn refresh_token(&self, _credentials: &Credentials) -> anyhow::Result<Credentials> {
24        anyhow::bail!("this auth strategy does not support token refresh")
25    }
26
27    fn validate_credentials(&self, credentials: &Credentials) -> bool;
28}