dog-auth-oauth
OAuth2 authentication strategy + orchestration helpers for DogRS.
This crate is intentionally provider-agnostic and transport-agnostic:
- OAuth provider specifics are implemented by you (or adapters) via a trait.
- HTTP redirects / callback endpoints belong in the server adapter.
What you get
Strategy
OAuthStrategy<P>(implementsdog_auth::core::AuthenticationStrategy)- Validates provider
- Accepts:
accessToken(already exchanged)code(can be exchanged by a registered provider)- optional
profile(pre-fetched)
- Optional entity linking (see
OAuthEntityResolver)
Provider plugin API
OAuthProvider<P>exchange_code(code, ctx) -> access_tokenfetch_profile(access_token, ctx) -> Option<Value>
Entity linking (for custom-only backends/services)
OAuthEntityResolver<P>resolve_entity(provider, profile, ctx) -> Option<Value>- Lets you link/create/load users using custom service methods (no
findrequired)
Service orchestrator
OAuthService<P>authenticate_callback(provider, payload, params, ctx, jwt_overrides)- Calls
dog-auth’sAuthenticationService::create(...) - Optional redirect resolution via
OAuthRedirect<P>
Install
[]
= { = "../dog-auth" }
= { = "../dog-auth-oauth" }
Optional features
oauth2-client
Enables a small, provider-agnostic helper built on the oauth2 crate:
OAuth2AuthorizationCodeProvider<P>
This lets you implement common OAuth2 authorization-code providers without wiring the oauth2 client manually in every app.
[]
= { = "../dog-auth-oauth", = ["oauth2-client"] }
Example:
use Arc;
use AuthenticationService;
use ;
Registering an OAuth provider
use Arc;
use AuthenticationService;
use ;
use HookContext;
use Value;
;
Using OAuthEntityResolver (custom services)
In the snippet below, TypeDbUserResolver is only a name to make the example concrete. The same pattern applies to any backend/service that prefers custom methods over CRUD.
use Arc;
use ;
use HookContext;
use Value;
;
// strategy = OAuthStrategy::new(&auth.base).with_entity_resolver(Arc::new(TypeDbUserResolver));
Notes
dog-auth-oauthdoes not implement an HTTP callback endpoint. Your web adapter should:- handle provider redirects
- gather callback payload
- call
OAuthService::authenticate_callback(...)or callAuthenticationService::create(...)directly.