Skip to main content

Crate larust_passport

Crate larust_passport 

Source
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_client rows 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_client is a plain async function - call it from your own seeder, console command, or xr tinker-equivalent script. Every other optional Tier-1 shim crate in this workspace (larust-sanctum/larust-socialite/…) is a pure library with no bespoke xr subcommand 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/authorize route 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” split larust-sanctum/ larust-socialite already establish, not a laravel/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::create_authorization_code;
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/authorize route 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 bespoke xr subcommand).
extractors
Request-time bearer-token validation - the sibling to crate::token (which issues tokens): these extractors check an incoming Authorization: Bearer {token} header against what crate::token stored, the same shape larust_sanctum::ApiAuth<U> already establishes for its own simpler bearer tokens.
token
Step 2: the token endpoint. Your own /oauth/token route handler parses the incoming grant_type (and whichever other form fields that grant needs) into a TokenRequest and calls exchange_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§

OAuthError
RFC 6749 §5.2’s own error vocabulary - every variant renders as 400 Bad Request with the exact {"error": "...", "error_description": "..."} JSON shape a real OAuth2 client parses programmatically (axum route handlers calling into this crate return Result<_, OAuthError> directly; its own axum::response::IntoResponse impl handles the rest). invalid_client is RFC-permitted at 400 when client authentication arrives in the request body (every grant this crate supports does) rather than the Authorization header, which is the only context this crate ever uses it in - 401 is correct only for the header-based case, not attempted here.