Start an OAuth authorization flow for the given method index. Returns the authorization URL and instructions for the user.
(
&self,
method_index: usize,
inputs: Option<HashMap<String, String>>,
)
| 85 | /// |
| 86 | /// Returns the authorization URL and instructions for the user. |
| 87 | pub async fn authorize( |
| 88 | &self, |
| 89 | method_index: usize, |
| 90 | inputs: Option<HashMap<String, String>>, |
| 91 | ) -> Result<PluginAuthorizeResult, PluginAuthError> { |
| 92 | if method_index >= self.meta.methods.len() { |
| 93 | return Err(PluginAuthError::InvalidMethodIndex { |
| 94 | plugin: self.client.name().to_string(), |
| 95 | index: method_index, |
| 96 | }); |
| 97 | } |
| 98 | |
| 99 | let inputs_value = inputs.map(|m| serde_json::to_value(m).unwrap_or(Value::Null)); |
| 100 | let result = self |
| 101 | .client |
| 102 | .auth_authorize(method_index, inputs_value) |
| 103 | .await?; |
| 104 | |
| 105 | Ok(PluginAuthorizeResult { |
| 106 | url: result.url, |
| 107 | instructions: result.instructions, |
| 108 | method: result.method, |
| 109 | }) |
| 110 | } |
| 111 | |
| 112 | /// Complete the OAuth callback with an optional authorization code. |
| 113 | pub async fn callback(&self, code: Option<&str>) -> Result<Value, PluginAuthError> { |
no test coverage detected