pub struct CredentialManager { /* private fields */ }Expand description
Resolves AuthConfig into a ready AuthCredential per the 8-step
workflow:
- validate config
- return immediately if
is_readyand not expired - try cache:
credential_service.load(app, user, key) - (preprocessor-stored) auth response (handled at runner layer)
- authorization-code flow with no exchanged credential →
NeedsUserConsent - exchange (service-account / authorization-code → access token)
- refresh if expired
- save back to credential service
Implementations§
Source§impl CredentialManager
impl CredentialManager
Sourcepub fn new(config: AuthConfig) -> Self
pub fn new(config: AuthConfig) -> Self
Construct with default exchangers + refreshers.
Sourcepub fn with_registries(
config: AuthConfig,
exchangers: Arc<ExchangerRegistry>,
refreshers: Arc<RefresherRegistry>,
providers: Arc<AuthProviderRegistry>,
) -> Self
pub fn with_registries( config: AuthConfig, exchangers: Arc<ExchangerRegistry>, refreshers: Arc<RefresherRegistry>, providers: Arc<AuthProviderRegistry>, ) -> Self
Construct with explicit registries (override for tests / custom providers).
Sourcepub fn credential_key(&self) -> String
pub fn credential_key(&self) -> String
The cache key this manager resolves to.
Sourcepub fn config(&self) -> &AuthConfig
pub fn config(&self) -> &AuthConfig
Borrowed view of the wrapped config.
Sourcepub async fn resolve(
&self,
app: &str,
user: &str,
credentials: Option<&dyn CredentialService>,
) -> Result<ResolveOutcome>
pub async fn resolve( &self, app: &str, user: &str, credentials: Option<&dyn CredentialService>, ) -> Result<ResolveOutcome>
Run the resolution workflow.
Sourcepub async fn begin_consent(
&self,
credentials: &dyn CredentialService,
) -> Result<ConsentRequest>
pub async fn begin_consent( &self, credentials: &dyn CredentialService, ) -> Result<ConsentRequest>
Start an OAuth 2.0 authorization-code consent flow.
Generates a fresh CSRF state + PKCE verifier via the oauth2 crate,
persists them in credentials keyed by an opaque flow_id, and
returns the URL the caller should redirect the user to. After the
provider redirects back, call Self::complete_consent with the
flow_id, the inbound state, and the inbound authorization code —
it will reject any mismatched state, perform the token exchange, and
save the resolved credential under the regular cache key.
Requires a credentials service: the verifier and state must
outlive the HTTP redirect, so transient None storage isn’t an
option here.
Sourcepub async fn complete_consent(
&self,
app: &str,
user: &str,
flow_id: &str,
callback_state: &str,
callback_code: &str,
credentials: &dyn CredentialService,
) -> Result<AuthCredential>
pub async fn complete_consent( &self, app: &str, user: &str, flow_id: &str, callback_state: &str, callback_code: &str, credentials: &dyn CredentialService, ) -> Result<AuthCredential>
Complete an OAuth 2.0 authorization-code consent flow.
callback_state and callback_code are the state and code query
params received at the provider’s redirect_uri. Validates that
callback_state == flow_id (the persisted state), exchanges the code
for an access token using the PKCE verifier persisted by
begin_consent, and writes the resolved credential under the regular
cache key for (app, user). Returns the exchanged credential.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for CredentialManager
impl !UnwindSafe for CredentialManager
impl Freeze for CredentialManager
impl Send for CredentialManager
impl Sync for CredentialManager
impl Unpin for CredentialManager
impl UnsafeUnpin for CredentialManager
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request