1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! The session credential port.
//!
//! A credential is the per-identity material that authenticates one user
//! against one homeserver. The SDK supports two credential types:
//!
//! - **Grant** ([`crate::actors::auth::grant::GrantCredential`]) — the default.
//! Long-lived user-signed grant + short-lived homeserver-minted access
//! opaque bearer, refreshed transparently.
//! - **Cookie** ([`crate::actors::auth::cookie::CookieCredential`]) —
//! legacy flow. A single opaque secret returned by `POST /session` and
//! replayed via the `Cookie` header.
//!
//! [`SessionCredential`] is the port (Clean Architecture sense). All
//! session-aware code (`PubkySession`, `SessionStorage`) talks to the
//! trait and never matches on a credential variant. The concrete adapters
//! live alongside their respective auth flows under `actors/auth/`.
//!
//! ## Why a trait, not an enum
//!
//! The previous design held a `Credential` enum and had `match` arms in
//! every method on `PubkySession` and `SessionStorage`. Adding a third
//! credential shape (or — more importantly — *removing* the cookie one)
//! meant editing every match. With a trait, those call sites become single
//! virtual dispatches and removing cookies becomes a one-folder deletion.
use Any;
use Debug;
use async_trait;
use PublicKey;
use SessionInfo;
use ;
use crate::;
/// Shared `revalidate` helper: a `404` or `401` from the homeserver means
/// the credential is gone (revoked / expired), not a transport failure.
pub
/// Behavior shared by every session credential type.
///
/// Implementations live alongside their auth protocol:
/// - [`crate::actors::auth::grant::GrantCredential`] — grant (default)
/// - [`crate::actors::auth::cookie::CookieCredential`] — legacy cookie flow
///
/// On native targets the boxed futures are `Send` so the trait is usable
/// behind `Arc<dyn SessionCredential>` from multi-threaded async runtimes.
/// On WASM (`wasm32`) the `?Send` variant is used because the browser event
/// loop is single-threaded and the underlying types contain `Rc`/`RefCell`.
///
// `async-trait` defaults to boxing futures as `Pin<Box<dyn Future + Send>>`,
// which doesn't compile on `wasm32-unknown-unknown` because the JS/WASM
// futures from `wasm-bindgen-futures` hold `Rc<RefCell<…>>` and aren't
// `Send`. The `?Send` variant drops that bound for WASM only; native keeps
// the `Send` bound so tokio's multi-threaded runtime stays happy.
pub