pub struct HttpWidgetAuth { /* private fields */ }Expand description
HTTP-backed provider: resolves agentId → AgentWidgetAuth by GETting
{base_url}/{agentId} from a host’s policy service, with TTL caching.
This is the generic mechanism a host installs instead of writing a custom
WidgetAuthProvider: stand up an endpoint that returns the
AgentWidgetAuth JSON ({ "allowed_origins": [...], "public_key": "..." })
for an agent, point HttpWidgetAuth at it, and embed-auth is enforced against
live data. (SmooAI backs this with an api-prime route over its agent DB.)
Response handling — chosen so a flaky policy service never silently opens a hole:
- 2xx → parse + cache the policy.
- 404 → cache
None(the agent legitimately has no policy; inWIDGET_AUTH_STRICTthe server then denies it). - 5xx / network / malformed body → return
Nonewithout caching, so the next connect retries. Combined with strict mode this fails closed; in permissive mode enforcement is off anyway.
Cached results (incl. 404s) are reused for ttl (default 60s) so a busy embed
doesn’t hammer the policy service on every WebSocket connect.
Implementations§
Source§impl HttpWidgetAuth
impl HttpWidgetAuth
Sourcepub fn new(base_url: impl Into<String>) -> Self
pub fn new(base_url: impl Into<String>) -> Self
Build a provider that resolves policies from base_url (e.g.
https://api.smoo.ai/internal/widget-auth). Uses a client with a 5s
timeout so a hung policy service can’t stall widget connects.
Sourcepub fn with_client(base_url: impl Into<String>, client: Client) -> Self
pub fn with_client(base_url: impl Into<String>, client: Client) -> Self
Build with a caller-supplied reqwest::Client (to share a pool / set
custom timeouts or TLS).
Sourcepub fn with_bearer(self, token: impl Into<String>) -> Self
pub fn with_bearer(self, token: impl Into<String>) -> Self
Send Authorization: Bearer <token> to the policy service (builder).
Trait Implementations§
Source§impl WidgetAuthProvider for HttpWidgetAuth
impl WidgetAuthProvider for HttpWidgetAuth
Source§fn agent_widget_auth<'life0, 'life1, 'async_trait>(
&'life0 self,
agent_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Option<AgentWidgetAuth>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn agent_widget_auth<'life0, 'life1, 'async_trait>(
&'life0 self,
agent_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Option<AgentWidgetAuth>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
agent_id, or None if the agent has none /
is unknown.Auto Trait Implementations§
impl !Freeze for HttpWidgetAuth
impl !RefUnwindSafe for HttpWidgetAuth
impl !UnwindSafe for HttpWidgetAuth
impl Send for HttpWidgetAuth
impl Sync for HttpWidgetAuth
impl Unpin for HttpWidgetAuth
impl UnsafeUnpin for HttpWidgetAuth
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request