MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / callback

Method callback

crates/opencode-server/src/oauth.rs:69–147  ·  view source on GitHub ↗
(
        &self,
        loader: &PluginLoader,
        provider_id: &str,
        code: Option<&str>,
    )

Source from the content-addressed store, hash-verified

67 }
68
69 pub async fn callback(
70 &self,
71 loader: &PluginLoader,
72 provider_id: &str,
73 code: Option<&str>,
74 ) -> Result<(), AuthError> {
75 let bridge = loader
76 .auth_bridge(provider_id)
77 .await
78 .ok_or_else(|| AuthError::OauthMissing(provider_id.to_string()))?;
79 let result = bridge
80 .callback(code)
81 .await
82 .map_err(|_| AuthError::OauthCallbackFailed)?;
83
84 let auth_type = result.get("type").and_then(|v| v.as_str()).unwrap_or("");
85 if auth_type != "success" {
86 return Err(AuthError::OauthCallbackFailed);
87 }
88
89 // Plugin callback can override target provider (e.g. copilot enterprise).
90 let target_provider = result
91 .get("provider")
92 .and_then(|v| v.as_str())
93 .unwrap_or(provider_id);
94
95 if let Some(key) = result
96 .get("key")
97 .and_then(|v| v.as_str())
98 .or_else(|| result.get("apiKey").and_then(|v| v.as_str()))
99 .or_else(|| result.get("token").and_then(|v| v.as_str()))
100 {
101 self.auth_manager
102 .set(
103 target_provider,
104 AuthInfo::Api {
105 key: key.to_string(),
106 },
107 )
108 .await;
109 return Ok(());
110 }
111
112 let access = result
113 .get("access")
114 .and_then(|v| v.as_str())
115 .unwrap_or_default()
116 .to_string();
117 let refresh = result
118 .get("refresh")
119 .and_then(|v| v.as_str())
120 .unwrap_or_default()
121 .to_string();
122
123 if access.is_empty() && refresh.is_empty() {
124 return Err(AuthError::OauthCallbackFailed);
125 }
126

Callers 2

oauth_callbackFunction · 0.45
plugin_auth_callbackFunction · 0.45

Calls 5

auth_bridgeMethod · 0.80
is_emptyMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected