pub struct OAuthService<S> { /* private fields */ }Expand description
OAuth authentication service supporting multiple providers.
Providers are registered by name via OAuthService::register.
Implementations§
Source§impl<S> OAuthService<S>where
S: UserRepository + SessionRepository + OAuthAccountRepository + Clone + Send + Sync + 'static,
impl<S> OAuthService<S>where
S: UserRepository + SessionRepository + OAuthAccountRepository + Clone + Send + Sync + 'static,
pub fn new( storage: S, events: EventBus, session_ttl_secs: i64, encryption_key: [u8; 32], ) -> Self
Sourcepub fn register(self, provider: impl OAuthProvider + 'static) -> Self
pub fn register(self, provider: impl OAuthProvider + 'static) -> Self
Register an OAuth provider.
Sourcepub fn begin(
&self,
provider_name: &str,
_redirect_uri: &str,
) -> Result<OAuthBeginResponse>
pub fn begin( &self, provider_name: &str, _redirect_uri: &str, ) -> Result<OAuthBeginResponse>
Begin an OAuth flow. Generate PKCE verifier+challenge and a random state.
Sourcepub async fn callback(
&self,
req: OAuthCallbackRequest<'_>,
) -> Result<(User, Session, String)>
pub async fn callback( &self, req: OAuthCallbackRequest<'_>, ) -> Result<(User, Session, String)>
Handle the OAuth callback. Exchange the code, fetch user info, upsert the OAuth account, find-or-create the user by email, and create a session.
req.expected_state must be the value returned by begin() (stored
server-side). req.received_state comes from the OAuth redirect query
param. A mismatch is treated as a CSRF attempt and rejected immediately.
Auto Trait Implementations§
impl<S> Freeze for OAuthService<S>where
S: Freeze,
impl<S> !RefUnwindSafe for OAuthService<S>
impl<S> Send for OAuthService<S>where
S: Send,
impl<S> Sync for OAuthService<S>where
S: Sync,
impl<S> Unpin for OAuthService<S>where
S: Unpin,
impl<S> UnsafeUnpin for OAuthService<S>where
S: UnsafeUnpin,
impl<S> !UnwindSafe for OAuthService<S>
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