mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-02 10:21:16 +08:00
feat(xai): add Grok OAuth device-flow backend and proxy routing
Add an xAI OAuth manager using the OAuth 2.0 Device Authorization Grant with endpoints resolved from xAI's OIDC discovery document. All HTTP goes through the app-managed proxy client. - Managed provider kind xai_oauth: forced openai_responses wire format, pinned api.x.ai base URL, bearer injection gated to the xAI origin, tokens registered for log redaction, single-auth-key takeover policy. - Token cache cannot bypass account state: cache hits re-validate account usability, refresh commits run under the mutation lock with a refresh-token CAS check, and pending logins are re-checked before an account is persisted. - Refresh classification: 401/403 with any body and 400 with a non-JSON body mark the account for re-auth; 429/5xx stay transient. - Shared auth_* commands dispatch to xAI with guard types mirroring the Copilot/Codex branches.
This commit is contained in:
@@ -71,6 +71,10 @@ impl Provider {
|
||||
self.provider_type() == Some("codex_oauth")
|
||||
}
|
||||
|
||||
pub fn is_xai_oauth(&self) -> bool {
|
||||
self.provider_type() == Some("xai_oauth")
|
||||
}
|
||||
|
||||
pub fn is_github_copilot(&self) -> bool {
|
||||
self.provider_type() == Some("github_copilot")
|
||||
|| self.claude_base_url_contains("githubcopilot.com")
|
||||
@@ -79,6 +83,7 @@ impl Provider {
|
||||
pub fn uses_managed_account_auth(&self) -> bool {
|
||||
self.is_github_copilot()
|
||||
|| self.is_codex_oauth()
|
||||
|| self.is_xai_oauth()
|
||||
|| self.claude_base_url_contains("chatgpt.com/backend-api/codex")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user