MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / handle_auth

Function handle_auth

nodedb/src/control/server/native/dispatch/auth.rs:18–57  ·  view source on GitHub ↗

Authenticate a native protocol client. Returns `(identity, warning)` — warning is non-empty when the account is in a password grace period or `must_change_password` is set. `OidcBearer` tokens are validated directly against the OIDC provider catalog (not the `JwksRegistry` provider list), enabling runtime `CREATE OIDC PROVIDER` without a server restart.

(
    state: &SharedState,
    auth_mode: &crate::config::auth::AuthMode,
    auth: &ProtoAuth,
    peer_addr: &str,
)

Source from the content-addressed store, hash-verified

16/// (not the `JwksRegistry` provider list), enabling runtime `CREATE OIDC PROVIDER`
17/// without a server restart.
18pub(crate) async fn handle_auth(
19 state: &SharedState,
20 auth_mode: &crate::config::auth::AuthMode,
21 auth: &ProtoAuth,
22 peer_addr: &str,
23) -> crate::Result<(AuthenticatedIdentity, Option<String>)> {
24 if let ProtoAuth::OidcBearer { token, .. } = auth {
25 let identity = crate::control::security::oidc::verify_bearer_token(state, token).await?;
26 state.audit_record(
27 crate::control::security::audit::AuditEvent::AuthSuccess,
28 Some(identity.tenant_id),
29 peer_addr,
30 &format!(
31 "OIDC bearer login: sub={} method=oidc_bearer",
32 identity.username
33 ),
34 );
35 state.auth_metrics.record_auth_success("oidc_bearer");
36 return Ok((identity, None));
37 }
38
39 let body = match auth {
40 ProtoAuth::Trust { username } => {
41 serde_json::json!({ "method": "trust", "username": username })
42 }
43 ProtoAuth::Password { username, password } => {
44 serde_json::json!({ "method": "password", "username": username, "password": password })
45 }
46 ProtoAuth::ApiKey { token } => {
47 serde_json::json!({ "method": "api_key", "token": token })
48 }
49 _ => {
50 return Err(crate::Error::BadRequest {
51 detail: "unsupported authentication method".into(),
52 });
53 }
54 };
55
56 super::super::super::session_auth::authenticate(state, auth_mode, &body, peer_addr).await
57}
58
59/// Respond to a ping with a pong.
60pub(crate) fn handle_ping(seq: u64) -> NativeResponse {

Callers 1

handle_authMethod · 0.50

Calls 4

verify_bearer_tokenFunction · 0.85
authenticateFunction · 0.85
audit_recordMethod · 0.80
record_auth_successMethod · 0.45

Tested by

no test coverage detected