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

Function handle_oidc_callback

crates/openshell-cli/src/oidc_auth.rs:379–435  ·  view source on GitHub ↗
(
    req: hyper::Request<hyper::body::Incoming>,
    state: Arc<CallbackState>,
)

Source from the content-addressed store, hash-verified

377}
378
379fn handle_oidc_callback(
380 req: hyper::Request<hyper::body::Incoming>,
381 state: Arc<CallbackState>,
382) -> Response<Full<Bytes>> {
383 if req.method() != Method::GET || !req.uri().path().starts_with("/callback") {
384 return Response::builder()
385 .status(StatusCode::NOT_FOUND)
386 .body(Full::new(Bytes::from("not found")))
387 .expect("response");
388 }
389
390 let query = req.uri().query().unwrap_or("");
391 let params: std::collections::HashMap<String, String> = query
392 .split('&')
393 .filter_map(|pair| {
394 let mut parts = pair.splitn(2, '=');
395 let key = percent_decode(parts.next()?);
396 let value = percent_decode(parts.next().unwrap_or(""));
397 Some((key, value))
398 })
399 .collect();
400
401 // Check for error response from the IdP.
402 if let Some(error) = params.get("error") {
403 let desc = params.get("error_description").map_or("", String::as_str);
404 debug!(error = %error, description = %desc, "OIDC auth error");
405 let _ = state.take_sender();
406 return html_response(
407 StatusCode::BAD_REQUEST,
408 &format!("Authentication failed: {error}. {desc}"),
409 );
410 }
411
412 let code = match params.get("code") {
413 Some(c) if !c.is_empty() => c,
414 _ => {
415 let _ = state.take_sender();
416 return html_response(StatusCode::BAD_REQUEST, "Missing authorization code.");
417 }
418 };
419
420 let received_state = params.get("state").map_or("", String::as_str);
421 if received_state != state.expected_state {
422 debug!("OIDC state mismatch");
423 let _ = state.take_sender();
424 return html_response(StatusCode::FORBIDDEN, "State parameter mismatch.");
425 }
426
427 if let Some(sender) = state.take_sender() {
428 let _ = sender.send(code.clone());
429 }
430
431 html_response(
432 StatusCode::OK,
433 "Authentication successful! You can close this tab and return to the terminal.",
434 )
435}
436

Callers 1

run_oidc_callback_serverFunction · 0.85

Calls 7

html_responseFunction · 0.85
pathMethod · 0.80
percent_decodeFunction · 0.70
nextMethod · 0.45
getMethod · 0.45
take_senderMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected