forge
Explore
Log in

Don't you dare go Hollow

im_old

Clone
★ 0

0 watching0 forksRustGPL-3.0755.6 KiB84318dcTahinli2 months ago77 commits

lib.rs43 lines, 1.6 KiBHistoryRawDownload
1//! im-client: the app-side SDK for im, in two halves.
2//!
3//! **The directory SDK** ([`directory`], always compiled): a consumer with
4//! its own OIDC client crate takes this and nothing else —
5//! [`directory::DirectoryClient`] pulls the roster and the photos and
6//! follows [`directory::DirectoryEvent`]s off the live stream, and
7//! [`directory::spawn_sync`] keeps a local mirror in step with backoff and
8//! resync. Build it with `default-features = false`.
9//!
10//! **The drop-in OIDC client** (the `oidc` feature, on by default):
11//! `im_client::mount(builder, config)` when it builds its router,
12//! `.discover()` as usual (the `/auth/login`, `/auth/callback`,
13//! `/auth/logout` routes register themselves), and
14//! `im_client::current_user(cx)` wherever it needs the person. im holds the
15//! central session; this half holds the app's side of it — an encrypted
16//! cookie holding the opaque session token, introspected against im on
17//! every request.
18//!
19//! The two halves share the crate's [`Error`]/[`Result`]. The OIDC half's
20//! routes register through the grammar's inventory, so a binary that also
21//! speaks OIDC through its own client crate must build this crate with
22//! `default-features = false`, or the two route sets collide at router
23//! build.
24
25pub mod directory;
26
27#[derive(Debug, thiserror::Error)]
28pub enum Error {
29 #[error("http: {0}")]
30 Http(String),
31 #[error("im refused: {0}")]
32 Refused(String),
33 #[error("bad token: {0}")]
34 Token(String),
35}
36
37pub type Result<T, E = Error> = std::result::Result<T, E>;
38
39#[cfg(feature = "oidc")]
40mod oidc;
41
42#[cfg(feature = "oidc")]
43pub use oidc::{Config, ImClient, User, current_user, mount};