CLIs and machines
Merge auth.oauth_router() at the root. A device makes a key, and sends it with a DPoP proof:
| Step | Who | Call |
|---|---|---|
| 1 | Device | POST /oauth/device_authorization with device_name, scope, data |
| 2 | Device | Shows user_code, the link, and its fingerprint (device::fingerprint) |
| 3 | Page | GET /auth/device/{code}: show the name, scope and fingerprint. The person compares |
| 4 | Page | POST /auth/device/{code}/approve with {"machine": false}. Needs a fresh login |
| 5 | Device | POST /oauth/token with the device code, every 5 seconds |
| 6 | Device | Later: 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_approvegets 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_revokedoes 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.ipisNonewithwithout_addresses. - A hook refuses with a
Refusal: a library code, or your own status and code (Refusal::App). GET /auth/devices?kind=userlists only one kind.- The request page and the list have the device’s
public_key(a canonical JWK), and the list has yourdata: 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.