Skip to main content

snaplink_sso/
lib.rs

1//! Framework-neutral Snaplink hosted login for public OAuth clients.
2//!
3//! The first login call returns the existing Console /login/ URL. The
4//! callback call validates state and issuer, then exchanges the authorization
5//! code with S256 PKCE. A web framework only needs to issue the redirect and
6//! pass the callback URL back to this client; no BFF is required.
7
8mod authorization;
9mod entitlement;
10mod error;
11mod license_file;
12mod login;
13mod preferences;
14mod session;
15mod state;
16mod transport;
17
18/// SDK-originated code for a failure response that carried no usable error
19/// code.
20///
21/// A caller that matches on [`SnaplinkError::OAuth`]'s `code` never receives an
22/// empty string, and a server code is never invented for such a response: an
23/// unreadable 500 must not look like a terminal `invalid_grant`. The `sdk_`
24/// prefix keeps it out of the server vocabulary in `docs/error-codes.md`.
25pub const UNCLASSIFIED_ERROR: &str = "sdk_response_unclassified";
26
27pub use authorization::{holds, Authorization, MenuButton, MenuNode};
28pub use entitlement::{
29    unix_now, Entitlement, Feature, InactiveReason, LicenseState, Limit, LimitGrant, PlanRef,
30};
31pub use error::SnaplinkError;
32pub use license_file::{EntitlementFile, LicenseError, LicenseTrust};
33pub use login::{
34    AccountContext, ActivationPreparation, LoginOptions, LoginResult, LoginSetupOptions,
35    SetupOptions, SnaplinkClient, TokenResponse,
36};
37pub use preferences::{
38    build_login_preference_handoff, from_stored_preferences, to_update_request, PreferenceError,
39    PresentationPreferences, PresentationPreferencesPatch, ThemeMode,
40};
41pub use state::{MemoryStateStore, StateStore};
42
43/// Classify a failure response the way this crate's own transport does.
44///
45/// A caller that injects a custom [`Transport`] receives the raw response and
46/// must turn it into an error; using this function keeps the code and status
47/// classification identical to the built-in one, including the
48/// [`UNCLASSIFIED_ERROR`] fallback for a response that carried no code.
49pub fn error_from_response(status: u16, body: &str) -> SnaplinkError {
50    parse_oauth_error(status, body)
51}
52#[cfg(feature = "blocking")]
53pub use transport::BlockingTransport;
54pub use transport::{
55    Method, ReqwestTransport, Transport, TransportError, TransportRequest, TransportResponse,
56};
57
58pub(crate) use login::{decode_token, parse_oauth_error, token_endpoint};