Skip to main content

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#![deny(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
12#![cfg_attr(
13    not(test),
14    deny(
15        clippy::unwrap_used,
16        clippy::unreachable,
17        clippy::expect_used,
18        clippy::panic,
19        clippy::unimplemented,
20        clippy::todo
21    )
22)]
23
24pub mod driver;
25mod error;
26pub mod normalize;
27pub mod providers;
28pub mod registry;
29pub mod types;
30
31pub use driver::{
32    ExternalAuthAuthorizationStart, ExternalAuthCallback, ExternalAuthProfile,
33    ExternalAuthProviderConfig, ExternalAuthProviderDescriptor, ExternalAuthProviderDriver,
34    ExternalAuthProviderTestCheck, ExternalAuthProviderTestResult,
35};
36pub use error::{ExternalAuthError, MapExternalAuthErr, Result};
37pub use registry::{ExternalAuthProviderRegistry, default_registry};
38pub use types::{
39    EXTERNAL_AUTH_TYPE_STORAGE_LEN, ExternalAuthProtocol, ExternalAuthProviderKind,
40    ExternalAuthProviderOptions, MicrosoftExternalAuthProviderOptions,
41    parse_external_auth_provider_options, serialize_external_auth_provider_options,
42};
43
44#[cfg(any(feature = "oauth2", feature = "oidc"))]
45pub(crate) const OUTBOUND_HTTP_USER_AGENT: &str =
46    concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
47
48#[cfg(any(feature = "oauth2", feature = "oidc"))]
49pub(crate) fn outbound_http_user_agent(provider: &driver::ExternalAuthProviderConfig) -> &str {
50    provider
51        .outbound_http_user_agent
52        .as_deref()
53        .map(str::trim)
54        .filter(|value| !value.is_empty())
55        .unwrap_or(OUTBOUND_HTTP_USER_AGENT)
56}