Expand description
Laravel’s laravel/passport - a full OAuth2 authorization server (RFC
6749), narrowed to the three grant types nearly every real integration
actually needs: Authorization Code with PKCE (RFC 7636, required -
“plain” challenge method is rejected outright, not just discouraged -
for every client, not only public ones, since there is no real
downside to requiring it and a real upside: a leaked/misconfigured
client secret stops being single-handedly sufficient to redeem a
stolen authorization code), Client Credentials (machine-to-machine,
confidential clients only), and Refresh Token (with rotation - see
token’s own doc comment for why the old refresh token is always
invalidated the moment a new one is issued, not left valid alongside
it).
Narrower than real Passport in three specific ways, all deliberate:
- One redirect URI per client, not Passport’s comma-separated
list. A real client registering multiple callback URLs (web +
mobile, say) registers multiple
client::create_clientrows instead - more rows, not a parsing/validation surface for a redirect-URI list this crate would otherwise own. - No
php artisan passport:client-equivalent interactive CLI.client::create_clientis a plain async function - call it from your own seeder, console command, orxr tinker-equivalent script. Every other optional Tier-1 shim crate in this workspace (larust-sanctum/larust-socialite/…) is a pure library with no bespokexrsubcommand of its own; this one follows the same precedent rather than being the first exception. - No scopes UI/consent-screen rendering. [
authorize:: create_authorization_code] is called by your own/oauth/authorizeroute handler once you’ve shown the user an approval screen and they’ve approved - the same “framework provides the mechanism, the app owns the actual route and its UI” splitlarust-sanctum/larust-socialitealready establish, not alaravel/passport-style auto-registered route+Blade view this crate would otherwise have to own and let every app style on its own.
See each submodule’s own doc comment for the full design of its own
piece: client (registration), authorize (step 1 - issuing a
code), token (step 2 - exchanging a code/refreshing/client-
credentials), extractors (request-time bearer-token validation).
Re-exported through larust_support::passport (see crates/ larust-support/src/lib.rs) so generated apps depend only on
larust-support, never on this crate directly.
Re-exports§
pub use authorize::AuthorizeRequest;pub use authorize::PkceMethod;pub use client::create_client;pub use client::NewClient;pub use extractors::has_scope;pub use extractors::require_scope;pub use extractors::OAuthAuth;pub use extractors::OAuthClientAuth;pub use token::exchange_token;pub use token::revoke_access_token;pub use token::revoke_refresh_token;pub use token::TokenRequest;pub use token::TokenResponse;
Modules§
- authorize
- Step 1 of the Authorization Code grant: issuing a code once your own
/oauth/authorizeroute has authenticated the user (via your app’s existing session/larust_auth::Auth<U>) and they’ve approved the request - this crate owns none of that UI, see this crate’s own doc comment for why. - client
- OAuth client registration - Laravel’s
php artisan passport:client, as a plain async function instead (see this crate’s own doc comment for why there’s no bespokexrsubcommand). - extractors
- Request-time bearer-token validation - the sibling to
crate::token(which issues tokens): these extractors check an incomingAuthorization: Bearer {token}header against whatcrate::tokenstored, the same shapelarust_sanctum::ApiAuth<U>already establishes for its own simpler bearer tokens. - token
- Step 2: the token endpoint. Your own
/oauth/tokenroute handler parses the incominggrant_type(and whichever other form fields that grant needs) into aTokenRequestand callsexchange_token- this crate owns none of the HTTP-layer form parsing/routing itself, the same “framework provides the mechanism, the app owns the route” split this crate’s own top-level doc comment already establishes.
Enums§
- OAuth
Error - RFC 6749 §5.2’s own error vocabulary - every variant renders as
400 Bad Requestwith the exact{"error": "...", "error_description": "..."}JSON shape a real OAuth2 client parses programmatically (axumroute handlers calling into this crate returnResult<_, OAuthError>directly; its ownaxum::response::IntoResponseimpl handles the rest).invalid_clientis RFC-permitted at400when client authentication arrives in the request body (every grant this crate supports does) rather than theAuthorizationheader, which is the only context this crate ever uses it in -401is correct only for the header-based case, not attempted here.