pub struct ApplicationIdentityProvider { /* private fields */ }Expand description
Identity provider whose get_credentials calls a host-supplied closure.
Use ApplicationIdentityProvider::new for an async closure (typical for
real token-acquisition flows) or ApplicationIdentityProvider::new_sync
for a synchronous closure (handy for tests and static credentials).
§Example
use std::sync::Arc;
use drasi_lib::identity::{ApplicationIdentityProvider, Credentials};
let provider = ApplicationIdentityProvider::new(|ctx| {
let host = ctx.get("hostname").unwrap_or("default").to_string();
async move {
// call into your existing auth code here
Ok(Credentials::UsernamePassword {
username: format!("user@{host}"),
password: "secret".into(),
})
}
});
let _provider: Arc<dyn drasi_lib::identity::IdentityProvider> = Arc::new(provider);Implementations§
Source§impl ApplicationIdentityProvider
impl ApplicationIdentityProvider
Sourcepub fn new<F, Fut>(callback: F) -> Selfwhere
F: Fn(&CredentialContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Credentials>> + Send + 'static,
pub fn new<F, Fut>(callback: F) -> Selfwhere
F: Fn(&CredentialContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Credentials>> + Send + 'static,
Create a provider backed by an async closure.
See also ApplicationIdentityProvider::new_sync for synchronous
callbacks.
Sourcepub fn new_sync<F>(callback: F) -> Self
pub fn new_sync<F>(callback: F) -> Self
Create a provider backed by a synchronous closure.
Convenience wrapper for callbacks that don’t need to await — the closure result is wrapped in a ready future.
See also ApplicationIdentityProvider::new for async callbacks.
Trait Implementations§
Source§impl Clone for ApplicationIdentityProvider
impl Clone for ApplicationIdentityProvider
Source§fn clone(&self) -> ApplicationIdentityProvider
fn clone(&self) -> ApplicationIdentityProvider
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ApplicationIdentityProvider
impl Debug for ApplicationIdentityProvider
Source§impl IdentityProvider for ApplicationIdentityProvider
impl IdentityProvider for ApplicationIdentityProvider
Source§fn get_credentials<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 CredentialContext,
) -> Pin<Box<dyn Future<Output = Result<Credentials>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_credentials<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 CredentialContext,
) -> Pin<Box<dyn Future<Output = Result<Credentials>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Fetch credentials for authentication. Read more
Source§fn clone_box(&self) -> Box<dyn IdentityProvider>
fn clone_box(&self) -> Box<dyn IdentityProvider>
Clone the provider into a boxed trait object.
Auto Trait Implementations§
impl Freeze for ApplicationIdentityProvider
impl !RefUnwindSafe for ApplicationIdentityProvider
impl Send for ApplicationIdentityProvider
impl Sync for ApplicationIdentityProvider
impl Unpin for ApplicationIdentityProvider
impl UnsafeUnpin for ApplicationIdentityProvider
impl !UnwindSafe for ApplicationIdentityProvider
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
Mutably borrows from an owned value. Read more