pub struct ExternalAuthProviderRegistry { /* private fields */ }Expand description
Registry of external authentication provider drivers keyed by provider kind.
The registry is the shared capability boundary for application services. Callers can use it to
list descriptors for admin surfaces, gate stored provider configs before a login flow starts,
and retrieve the runtime driver for a validated provider. The registry deliberately does not
know how providers are stored in a product database; applications adapt their own rows into
ExternalAuthProviderConfig immediately before using this type.
Implementations§
Source§impl ExternalAuthProviderRegistry
impl ExternalAuthProviderRegistry
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Creates an empty registry with no built-in provider drivers.
This is useful for applications that want a fully explicit provider list, tests that need deterministic registration behavior across Cargo feature sets, or plugin hosts that build a registry from externally supplied drivers.
Sourcepub fn with_external_registrations<F>(configure: F) -> Result<Self>
pub fn with_external_registrations<F>(configure: F) -> Result<Self>
Creates a built-in registry and lets an external system append registrations.
This is the intended integration point for application-level extension systems: the caller
receives a mutable registry, calls ExternalAuthProviderRegistry::add for each external
driver it wants to expose, and returns any setup error. Built-in drivers are registered
before the callback runs, so external systems cannot accidentally replace them through the
non-replacing add API.
Sourcepub fn add<D>(&mut self, driver: D) -> Result<()>where
D: ExternalAuthProviderDriver + 'static,
pub fn add<D>(&mut self, driver: D) -> Result<()>where
D: ExternalAuthProviderDriver + 'static,
Adds a driver if its provider kind is not already registered.
Use this for product-specific or plugin-provided drivers. Duplicate provider kinds return a configuration error instead of replacing the existing driver, which keeps built-in behavior stable when external systems are enabled.
Sourcepub fn add_arc(
&mut self,
driver: Arc<dyn ExternalAuthProviderDriver>,
) -> Result<()>
pub fn add_arc( &mut self, driver: Arc<dyn ExternalAuthProviderDriver>, ) -> Result<()>
Adds an already shared driver if its provider kind is not already registered.
Sourcepub fn register<D>(&mut self, driver: D) -> Result<()>where
D: ExternalAuthProviderDriver + 'static,
pub fn register<D>(&mut self, driver: D) -> Result<()>where
D: ExternalAuthProviderDriver + 'static,
Registers or replaces a driver for its provider kind.
Use this only when replacement is intentional, such as tests or product-level overrides. The driver must still report a descriptor for the same provider kind that it registers.
Sourcepub fn register_arc(
&mut self,
driver: Arc<dyn ExternalAuthProviderDriver>,
) -> Result<()>
pub fn register_arc( &mut self, driver: Arc<dyn ExternalAuthProviderDriver>, ) -> Result<()>
Registers or replaces an already shared driver for its provider kind.
Sourcepub fn supported_kinds(
&self,
) -> impl Iterator<Item = ExternalAuthProviderKind> + '_
pub fn supported_kinds( &self, ) -> impl Iterator<Item = ExternalAuthProviderKind> + '_
Iterates over registered provider kinds.
Sourcepub fn contains(&self, kind: ExternalAuthProviderKind) -> bool
pub fn contains(&self, kind: ExternalAuthProviderKind) -> bool
Returns whether a driver for kind is registered.
Sourcepub fn descriptors(&self) -> Vec<ExternalAuthProviderDescriptor>
pub fn descriptors(&self) -> Vec<ExternalAuthProviderDescriptor>
Returns registered provider descriptors sorted by provider kind.
Sourcepub fn descriptor_for(
&self,
kind: ExternalAuthProviderKind,
) -> Result<ExternalAuthProviderDescriptor>
pub fn descriptor_for( &self, kind: ExternalAuthProviderKind, ) -> Result<ExternalAuthProviderDescriptor>
Returns the descriptor for a registered provider kind.
Sourcepub fn ensure_provider_supported(
&self,
kind: ExternalAuthProviderKind,
) -> Result<()>
pub fn ensure_provider_supported( &self, kind: ExternalAuthProviderKind, ) -> Result<()>
Ensures that a provider kind is enabled in this registry.
This is useful for service-layer guards that need to reject disabled provider kinds without constructing a login flow or exposing the underlying driver.
Sourcepub fn validate_provider_config(
&self,
provider: &ExternalAuthProviderConfig,
) -> Result<ExternalAuthProviderDescriptor>
pub fn validate_provider_config( &self, provider: &ExternalAuthProviderConfig, ) -> Result<ExternalAuthProviderDescriptor>
Validates that a product-owned provider config matches a registered driver descriptor.
This catches configuration drift before provider-specific network calls run. The method checks that the provider kind is enabled and that the stored protocol matches the driver’s declared protocol. It returns the descriptor so callers can keep using the capability data without another registry lookup.
Sourcepub fn driver_for_provider(
&self,
provider: &ExternalAuthProviderConfig,
) -> Result<Arc<dyn ExternalAuthProviderDriver>>
pub fn driver_for_provider( &self, provider: &ExternalAuthProviderConfig, ) -> Result<Arc<dyn ExternalAuthProviderDriver>>
Returns the registered driver for a provider config after validating the config boundary.
Product services should prefer this method when starting authorization, exchanging a callback, or testing a provider because it applies the same registry-level gates for every flow.
Sourcepub fn get_driver(
&self,
kind: ExternalAuthProviderKind,
) -> Result<Arc<dyn ExternalAuthProviderDriver>>
pub fn get_driver( &self, kind: ExternalAuthProviderKind, ) -> Result<Arc<dyn ExternalAuthProviderDriver>>
Returns a registered driver by provider kind.
Sourcepub fn oidc(&self) -> Result<Arc<dyn ExternalAuthProviderDriver>>
pub fn oidc(&self) -> Result<Arc<dyn ExternalAuthProviderDriver>>
Returns the OIDC driver from this registry.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ExternalAuthProviderRegistry
impl !RefUnwindSafe for ExternalAuthProviderRegistry
impl Send for ExternalAuthProviderRegistry
impl Sync for ExternalAuthProviderRegistry
impl Unpin for ExternalAuthProviderRegistry
impl UnsafeUnpin for ExternalAuthProviderRegistry
impl !UnwindSafe for ExternalAuthProviderRegistry
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more