MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / ensure_valid_oidc_token

Function ensure_valid_oidc_token

crates/openshell-cli/src/oidc_auth.rs:265–285  ·  view source on GitHub ↗

Ensure we have a valid OIDC token for the given gateway, refreshing if needed. Returns the access token string.

(gateway_name: &str, insecure: bool)

Source from the content-addressed store, hash-verified

263///
264/// Returns the access token string.
265pub async fn ensure_valid_oidc_token(gateway_name: &str, insecure: bool) -> Result<String> {
266 let bundle =
267 openshell_bootstrap::oidc_token::load_oidc_token(gateway_name).ok_or_else(|| {
268 miette::miette!(
269 "No OIDC token stored for gateway '{gateway_name}'.\n\
270 Authenticate with: openshell gateway login"
271 )
272 })?;
273
274 if !openshell_bootstrap::oidc_token::is_token_expired(&bundle) {
275 return Ok(bundle.access_token);
276 }
277
278 debug!(
279 gateway = gateway_name,
280 "OIDC token expired, attempting refresh"
281 );
282 let refreshed = oidc_refresh_token(&bundle, insecure).await?;
283 openshell_bootstrap::oidc_token::store_oidc_token(gateway_name, &refreshed)?;
284 Ok(refreshed.access_token)
285}
286
287// ── Helpers ──────────────────────────────────────────────────────────
288

Callers

nothing calls this directly

Calls 4

load_oidc_tokenFunction · 0.85
is_token_expiredFunction · 0.85
oidc_refresh_tokenFunction · 0.85
store_oidc_tokenFunction · 0.85

Tested by

no test coverage detected