Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CLIs and machines

Merge auth.oauth_router() at the root. A device makes a key, and sends it with a DPoP proof:

StepWhoCall
1DevicePOST /oauth/device_authorization with device_name, scope, data
2DeviceShows user_code, the link, and its fingerprint (device::fingerprint)
3PageGET /auth/device/{code}: show the name, scope and fingerprint. The person compares
4PagePOST /auth/device/{code}/approve with {"machine": false}. Needs a fresh login
5DevicePOST /oauth/token with the device code, every 5 seconds
6DeviceLater: POST /oauth/token with a signed assertion. There is no refresh token to lose

scope and data mean what your application wants. Decide in the hook:

use auth_chad::{Authenticated, Store};
use auth_chad::axum::Hooks;
use auth_chad::core::rows::DeviceKind;

#[derive(Clone)]
struct App;

impl<S: Store> Hooks<S> for App {
    async fn may_request_device(&self, scope: &str, _data: &str) -> bool {
        scope == "user" || scope == "machine"   // anything else: invalid_scope
    }

    async fn may_approve(&self, _who: &Authenticated, scope: &str, _data: &str) -> bool {
        scope == "user"   // also who may see and deny the request
    }

    fn device_kind(&self, scope: &str, _data: &str, _asked: DeviceKind) -> Option<DeviceKind> {
        Some(if scope == "machine" { DeviceKind::Machine } else { DeviceKind::User })   // the scope decides
    }
}
  • commit_approve gets the approval’s own "app" field and the writes: add your rows, for example a key sealed to the device, in the same commit. commit_revoke does the same for a revocation, and can refuse it.
  • These hooks get By { who, ip }: who acts, and the address of the request, for your own audit rows. ip is None with without_addresses.
  • A hook refuses with a Refusal: a library code, or your own status and code (Refusal::App).
  • GET /auth/devices?kind=user lists only one kind.
  • The request page and the list have the device’s public_key (a canonical JWK), and the list has your data: an application can show a fingerprint of its own.

A user device acts as the user. A machine acts as itself (Subject::Machine). Neither is ever fresh.