Skip to main content

claim_router

Function claim_router 

Source
pub fn claim_router(kernel: Kernel) -> Router
Expand description

The claim route of kernel’s device pairing (spec 3.3 §10 K2) at /api/kernel/pairing/claim, which needs no caller since the code is the credential: merge it with ServerBuilder::add_root_routes, outside the auth middleware and inside the host and origin checks. Empty when the kernel pairs no devices.

A server that serves the kernel’s routes to devices needs all three pieces: the routes behind a DeviceTokenExtractor, this claim route, and guard_devices around the built app, which checks a device’s decision for its risk and records it; the extractor refuses a device’s decision the guard did not admit.

§Example

use std::sync::Arc;
use adk_kernel::pairing::DeviceTokenExtractor;

let pairing = kernel.config().control.pairing.clone().expect("the kernel pairs devices");
let extractor = DeviceTokenExtractor::new(pairing).with_fallback(bearer);
let app = adk_server::ServerBuilder::new(config.with_request_context(Arc::new(extractor)))
    .add_api_routes(adk_kernel::control::router(kernel.clone()))
    .add_root_routes(adk_kernel::control::claim_router(kernel.clone()))
    .build();
let app = adk_kernel::control::guard_devices(&kernel, app);