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

Function try_validate_jwt

nodedb/src/control/server/http/auth.rs:33–42  ·  view source on GitHub ↗

Try to validate a Bearer token as a JWT via the JWKS registry. Returns `Some(identity)` if the token is a valid JWT with 2 dots and the registry verifies the signature. Returns `None` otherwise.

(state: &AppState, token: &str)

Source from the content-addressed store, hash-verified

31/// Returns `Some(identity)` if the token is a valid JWT with 2 dots and
32/// the registry verifies the signature. Returns `None` otherwise.
33fn try_validate_jwt(state: &AppState, token: &str) -> Option<AuthenticatedIdentity> {
34 if token.matches('.').count() == 2
35 && let Some(ref registry) = state.shared.jwks_registry
36 && let Ok(identity) = tokio::runtime::Handle::current().block_on(registry.validate(token))
37 {
38 Some(identity)
39 } else {
40 None
41 }
42}
43
44/// Resolve an authenticated identity from HTTP headers.
45///

Callers 2

resolve_identityFunction · 0.85
resolve_authFunction · 0.85

Calls 4

currentFunction · 0.85
countMethod · 0.45
matchesMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected