Skip to content

Commit 5ed845d

Browse files
committed
feat: add refresh_access_token_async to Python Config
1 parent 282d83d commit 5ed845d

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

python/src/config.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,30 @@ impl Config {
233233
.refresh_access_token_blocking(expired_at.map(|t| t.0))
234234
.map_err(ErrorNewType)?)
235235
}
236+
237+
/// Async version of :meth:`Config.refresh_access_token`. Returns an
238+
/// awaitable; must be awaited inside asyncio.
239+
///
240+
/// Args:
241+
/// expired_at: The expiration time of the access token (default: 90
242+
/// days from now).
243+
///
244+
/// Returns:
245+
/// New access token string
246+
#[pyo3(signature = (expired_at = None))]
247+
pub fn refresh_access_token_async(
248+
&self,
249+
py: Python<'_>,
250+
expired_at: Option<PyOffsetDateTimeWrapper>,
251+
) -> PyResult<Py<PyAny>> {
252+
let config = self.0.clone();
253+
pyo3_async_runtimes::tokio::future_into_py(py, async move {
254+
config
255+
.refresh_access_token(expired_at.map(|t| t.0))
256+
.await
257+
.map_err(ErrorNewType)
258+
.map_err(PyErr::from)
259+
})
260+
.map(|b| b.unbind())
261+
}
236262
}

0 commit comments

Comments
 (0)