aster_forge_external_auth/
lib.rs

1//! Feature-gated external authentication provider drivers for Aster services.
2//!
3//! This crate contains the provider-neutral external authentication contract plus reusable
4//! implementations for `OpenID` Connect, generic `OAuth2`, and selected fixed-endpoint providers. It
5//! deliberately avoids application database models, account entities, and HTTP handler concerns:
6//! product crates map their stored provider rows into [`ExternalAuthProviderConfig`] and map
7//! [`ExternalAuthError`] into their own API error type. Built-in connectors are controlled by Cargo
8//! features so each backend can compile only the providers it supports. The default feature set
9//! enables `oidc` and generic `oauth2`; dedicated connectors such as `github`, `google`,
10//! `microsoft`, and `qq` must be enabled explicitly.
11#![cfg_attr(
12    not(test),
13    deny(
14        clippy::unwrap_used,
15        clippy::unreachable,
16        clippy::expect_used,
17        clippy::panic,
18        clippy::unimplemented,
19        clippy::todo
20    )
21)]
22
23pub mod driver;
24mod error;
25pub mod normalize;
26pub mod providers;
27pub mod registry;
28pub mod types;
29
30pub use driver::{
31    ExternalAuthAuthorizationStart, ExternalAuthCallback, ExternalAuthProfile,
32    ExternalAuthProviderConfig, ExternalAuthProviderDescriptor, ExternalAuthProviderDriver,
33    ExternalAuthProviderTestCheck, ExternalAuthProviderTestResult,
34};
35pub use error::{ExternalAuthError, MapExternalAuthErr, Result};
36pub use registry::{ExternalAuthProviderRegistry, default_registry};
37pub use types::{
38    EXTERNAL_AUTH_TYPE_STORAGE_LEN, ExternalAuthProtocol, ExternalAuthProviderKind,
39    ExternalAuthProviderOptions, MicrosoftExternalAuthProviderOptions,
40    parse_external_auth_provider_options, serialize_external_auth_provider_options,
41};
42
43#[cfg(any(feature = "oauth2", feature = "oidc"))]
44pub(crate) const OUTBOUND_HTTP_USER_AGENT: &str =
45    concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
46
47#[cfg(any(feature = "oauth2", feature = "oidc"))]
48pub(crate) fn outbound_http_user_agent(provider: &driver::ExternalAuthProviderConfig) -> &str {
49    provider
50        .outbound_http_user_agent
51        .as_deref()
52        .map(str::trim)
53        .filter(|value| !value.is_empty())
54        .unwrap_or(OUTBOUND_HTTP_USER_AGENT)
55}