Laravel Rust is a young framework. It gives you routing, models, queues, mail, and auth, but it had no authorization server. If your app needed to hand out tokens to other apps, you had to build that part yourself.

rupirate-passport fills that gap. It is the Laravel Passport idea, rebuilt natively in Rust for Laravel Rust. Your app becomes the authorization server. Another app asks your users for permission, and your app hands it tokens. The crate does the server side: clients, authorization codes with PKCE, refresh tokens, personal access tokens, scopes, revocation, and introspection. It also speaks OpenID Connect, device flow, PAR, and DPoP.

It is version 0.1.4, published on crates.io. The code lives in the rupirate repo on GitHub, under rupirate/. The full guide is in the crate's DOCUMENTATION.md.

What it covers

This is not a thin wrapper. It is a full server, and the feature list is long:

  • Authorization codes with PKCE (S256 only, plain is refused), client credentials, refresh tokens with rotation, and personal access tokens.
  • OpenID Connect: ID tokens, UserInfo, and a discovery document. The openid scope is a protocol scope, not a resource permission.
  • JWT access tokens, opt in with access_token_format = "jwt". Opaque tokens stay the default, and the row is still written, so revocation works the same either way.
  • Device authorization (RFC 8628), pushed authorization requests (RFC 9126), and DPoP sender-constrained tokens (RFC 9449).
  • Token exchange (RFC 8693), JWT client auth (RFC 7523), JAR (RFC 9101), and rich authorization requests (RFC 9396).
  • Dynamic client registration (RFC 7591/7592), RP-initiated logout plus front and back-channel logout, session management, step-up auth with prompt, max_age, and acr_values, pairwise subjects, per-scope consent with remembered consent, and resource indicators (RFC 8707).
  • CIBA, the backchannel authentication flow, with an app hook that decides approve, deny, or pending.
  • An admin JSON API, a persistent audit trail with the passport:audit command, and a verify-only feature so a resource server can check tokens without pulling in the server code.
  • FAPI 2.0 readiness, including JARM response modes. Full FAPI 2.0 compliance is not claimed.

Two grants are missing on purpose: the password grant and the implicit grant. Both are deprecated, and OAuth 2.1 removes both. Users sign in through your own login page. Passport only ever sees the session that login made.

Install

Add the crate from crates.io:

[dependencies] rupirate-passport = "0.1.4" 

Or, from a local checkout of the repo, use the path dependency:

[dependencies] rupirate-passport = { path = "../rupirate-passport" } 

Register the provider:

Application::configure().with_providers(|providers| { providers.add(rupirate_passport::PassportServiceProvider); }) 

Then run migrate once. The package ships 18 migration files for 13 tables: oauth_clients, oauth_access_tokens, oauth_refresh_tokens, oauth_auth_codes, oauth_device_codes, oauth_par_requests, oauth_dpop_jtis, oauth_dpop_nonces, oauth_client_assertion_jtis, oauth_consents, oauth_registration_tokens, oauth_ciba_requests, and oauth_audit_log.

The two servers

Every example in the docs uses the same two servers, so this article does too. Server 1 is a notes app at auth.example.com. It installs Passport. Server 2 is another app at app.example. It wants to read a user's notes. That is the whole story of this crate.

Quickstart

1. Create a client for Server 2

$ laravel passport:client --name "My App" --redirect https://app.example/callback Client ID: 1 Client secret: hidden (pass --show-secret to display it at creation) 

The secret is shown once. It is never stored in plaintext. With no encryption key it is stored as a SHA-256 hash. With secret_encryption_key set it is stored AES-256-GCM-encrypted, so client_secret_jwt can use it. Losing that encryption key means rotating every encrypted secret, so back it up.

2. Send the user to authorize

Server 2 builds a PKCE pair (a random verifier and its S256 challenge) and redirects the user to Server 1:

GET https://auth.example.com/oauth/authorize ?response_type=code &client_id=1 &redirect_uri=https://app.example/callback &scope=notes.read &state=xyz &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM &code_challenge_method=S256 

The authorize routes run behind the framework's Authenticate middleware, so a guest never reaches the consent screen. The user sees what Server 2 is asking for, with a checkbox per scope when scope descriptions are configured, and approves it. Consent can be remembered, so the user is not asked again for the same scopes.

3. Handle the callback

Server 1 redirects back to https://app.example/callback?code=AUTH_CODE&state=xyz. Server 2 checks the state, then exchanges the code at the token endpoint:

POST https://auth.example.com/oauth/token Content-Type: application/x-www-form-urlencoded grant_type=authorization_code &code=AUTH_CODE &redirect_uri=https://app.example/callback &client_id=1 &client_secret=YOUR_CLIENT_SECRET &code_verifier=YOUR_VERIFIER 

The response is a token pair: an access token, a refresh token, and, when the openid scope was asked for, an ID token.

4. Protect a route on Server 1

use laravel::http::Request; use rupirate_passport::{authenticate_with_passport, require_passport_scope, AccessToken}; route .get("/api/notes", notes) .middleware(authenticate_with_passport) .middleware(require_passport_scope("notes.read".to_string())); pub async fn notes(request: Request) -> String { let token = request.extension::<AccessToken>().unwrap(); // A client-credentials token has no user. Never read it as user 0. // Match on `user_id`: `Some(id)` is a user token, `None` is a client token. match token.user_id { Some(id) => format!("user {id}"), None => format!("client {}", token.client_id), } } 

5. Issue a token directly

For a script or a test, skip the browser flow and mint a personal access token:

use laravel::container::Inject; use rupirate_passport::Passport; async fn issue(passport: Inject<Passport>) -> laravel::Result<String> { let pair = passport .personal_access_token(1, 1, "api", &[]) .await .map_err(|error| laravel::Error::msg(error.to_string()))?; Ok(pair.access_token) } 

The other flows

The authorization code flow above is the main one. The rest are short:

  • Client credentials. A service with no user asks for a token with its own client id and secret. The token has user_id set to None, and handlers must match on that instead of reading a user id of zero.
  • Refresh tokens. Every refresh rotates: the old token is revoked and a new pair is issued. If a rotated refresh token is ever presented again, the whole family is revoked, after a 10-second grace window for a client that retried and missed the new pair.
  • Device flow (RFC 8628). A TV or CLI asks POST /oauth/device/code for a device code and a user code, shows the user a verification URI, and polls the token endpoint until the user approves on another device. Only hashes of the codes are stored.
  • PAR (RFC 9126). The client pushes the authorize parameters to POST /oauth/par first and gets a single-use request_uri that lives for 60 seconds. The browser then carries only that URI, so the parameters never sit in a URL.
  • Token exchange (RFC 8693). Exchange an access token for a new one, with scope subsetting and the actor chain in the JWT act claim.
  • CIBA. The client calls POST /oauth/bc-authorize and the app decides out of band, through the with_ciba_authenticator hook: approve, deny, or pending.

OpenID Connect and signing keys

Ask for the openid scope and the code exchange returns an ID token alongside the access token. It is an RS256 JWT with iss, sub, aud, exp, iat, auth_time, and nonce. UserInfo lives at GET/POST /oauth/userinfo, and discovery at GET /.well-known/openid-configuration. The JWKS is at GET /.well-known/jwks.json.

UserInfo releases a claim only for a scope the token carries: profile for name claims, email for email claims, and so on. A claim for an ungranted scope is dropped, and a custom claim with no standard mapping is dropped too. sub is always present. A token without the openid scope is refused with 403. A DPoP-bound token needs a valid proof at UserInfo, just like at any protected resource.

Set jwt_private_key_pem in the environment and that key signs ID tokens and JWT access tokens. With no key configured, an ephemeral RSA-2048 pair is generated on first use and rotates on every restart, so production must set a key.

Rotation is built in:

// 1. Add the new key. It becomes the current signing key at once, // and its kid appears in the JWKS. The old key stays too. let new_kid = passport.add_signing_key(NEW_PRIVATE_PEM)?; let current = passport.current_signing_kid()?; assert_eq!(current, new_kid); // 2. Wait until every token the old key signed has expired. // Access tokens live 60 minutes by default, ID tokens are // short-lived, and refresh tokens are never signed. // 3. Retire the old key. Tokens signed with it stop verifying. let retired = passport.retire_signing_key(OLD_KID)?; 

One honest detail: keys added or retired this way live only in the running process. They are lost on restart and not shared across instances. A real rotation is a config change. Set PASSPORT_JWT_PRIVATE_KEY_PEM to the new key, put the old key's public PEM in PASSPORT_JWT_ADDITIONAL_PUBLIC_KEYS_PEM, then restart.

DPoP: binding tokens to a key

DPoP (RFC 9449) ties a token to the client's key, so a stolen token is useless without it. The token endpoint accepts an optional DPoP proof. A valid proof binds the issued token to the proof's thumbprint (cnf.jkt on the row, token_type: DPoP). A bound token refreshes only with a proof for the same key.

Resource access uses a separate middleware, attached instead of the bearer one:

use rupirate_passport::require_passport_dpop; 

It requires the proof's ath to match the token and its key to match cnf.jkt. A bound token presented as a plain Bearer token is rejected. Proofs work with RS256 and ES256, and the server issues single-use DPoP-Nonce values.

Client auth

Clients authenticate four ways: client_secret_basic, client_secret_post, private_key_jwt, and client_secret_jwt (RFC 7523). The JWT methods check assertion jti values, and each jti is single-use. private_key_jwt verifies RS256 or ES256 against the client's registered JWKS, set with set_client_jwks.

client_secret_jwt signs with the raw secret as its HMAC key, as the standard requires. That only works when secrets are stored encrypted, which is why secret_encryption_key exists. Without it, client_secret_jwt is rejected with a clear error and is not advertised in discovery. Hashed secrets keep working for basic and post auth.

Config

Everything is set in code or in the environment. The defaults are sane: routes on, prefix /oauth, login /login, access tokens 60 minutes, refresh tokens 14 days, auth codes 10 minutes, personal tokens 1 year, no scopes configured, PKCE required for public clients.

The settings you will touch first:

Key Env var Default Meaning
prefix PASSPORT_PREFIX "/oauth" URL prefix of the routes
issuer PASSPORT_ISSUER "http://localhost:8000" Issuer of ID and JWT tokens; set it to your app base URL in production
jwt_private_key_pem PASSPORT_JWT_PRIVATE_KEY_PEM empty RSA private key; empty means an ephemeral keypair
secret_encryption_key PASSPORT_SECRET_ENCRYPTION_KEY empty Base64 32-byte key encrypting client secrets at rest
pkce_mode PASSPORT_PKCE_MODE "public" Which clients must use PKCE: public, all, or off
access_token_format PASSPORT_ACCESS_TOKEN_FORMAT "opaque" opaque or jwt
token_rate_limit_per_minute PASSPORT_TOKEN_RATE_LIMIT_PER_MINUTE 60 Requests per minute; 0 disables it
subject_type PASSPORT_SUBJECT_TYPE "public" public or pairwise subjects
admin_api PASSPORT_ADMIN_API false Enable the admin API; it also needs admin_token

The full list, with every env name and default, is in the guide under Configuration.

Admin and audit

The admin API is a JSON API at GET /oauth/admin/clients, /tokens, /stats, and /audit. It is gated by two flags, admin_api and admin_token, and answers 404 when either is off. Users can also manage their own tokens through session-authenticated routes: GET /oauth/tokens, POST /oauth/tokens/{id}/revoke, GET /oauth/authorized-apps, and POST /oauth/authorized-apps/{client_id}/revoke. Revoking an authorized app kills its tokens and forgets its remembered consent.

Every significant event is written to oauth_audit_log: issuance, rotation, revocation, reuse, replays, cross-client introspection. Read it with list_audit_events or print the 20 most recent with laravel passport:audit. Run laravel passport:purge on a schedule, daily is enough. A revoked refresh token is kept until it expires, because it is the tripwire that detects reuse.

Security decisions worth knowing

A few choices shape the whole design, and they are worth stating plainly:

  • Refresh reuse revokes the family. A rotated refresh token presented again means the token was stolen, so the whole family dies. The 10-second grace window exists only for a client that retried and missed the new pair.
  • Code exchange is atomic. Two concurrent exchanges of one code cannot both succeed, and a failure cannot leave a code claimed with no pair issued.
  • PKCE is mandatory for public clients. A public client must send an S256 challenge at authorize. plain is rejected everywhere.
  • The authorize request is bound to the session. The GET stashes the request in the session. The POST reads it back and ignores the hidden form fields, so tampering cannot change the client, redirect URI, scopes, or PKCE challenge.
  • Revocation authenticates the client. A client may revoke only its own tokens, and revoking a refresh token also revokes its access token. The answer is 200 either way, so no existence leak.
  • Rate limiting. The token, revoke, introspect, device-code, PAR, registration, and CIBA routes are throttled to 60 requests per minute per client IP by default.
  • Redirect URIs are strict. Confidential clients accept only https, or http on loopback. Public clients may also use a reverse-domain scheme like com.example.app:/callback. Bare schemes, javascript:, data:, fragments, and whitespace are rejected.
  • A user validator hook closes a real gap. The Authenticate middleware alone does not cover refresh, exchange, or introspection. Register with_user_validator and the server checks the user at authorize, refresh, token exchange, device and CIBA approval, and introspection. A rejected user gets invalid_grant or active: false.

What it does not do

Honest limits, stated plainly:

  • No mTLS (RFC 8705). The framework exposes only the socket address to handlers, so there is no TLS peer certificate to read. No fake version is implemented.
  • No SAML2 bearer grant (RFC 7522). No XML canonicalization or XMLDSig crate exists in the registry this workspace builds from, and hand-rolled canonicalization risks accepting forgeries. An unverified assertion is worse than no grant.
  • No OIDC conformance claim. The suite needs a running server with specific profiles, and it has never been run here. Conformance is not claimed.
  • No password grant and no implicit grant. By design, permanently.
  • The audit was the author's own, not independent. The hardening pass was a self-review: a full read of the crate plus a hostile audit, with 169 tests passing and clippy clean at zero warnings. It is not a third-party audit, and it is not presented as one.
  • Introspection is client-scoped. A token only answers to the client it was issued to, unless that client is marked as a resource server. The server does not check the token's audience. A resource server must check aud and scope in the response itself.

Where to go from here

The crate is on crates.io as rupirate-passport 0.1.4, and the code is in the rupirate repo. The full guide walks through every flow step by step with the same two servers. Start there when this article runs out.

Two companion crates in the same repo cover the other half of app auth: rupirate-sanctum and rupirate-cashier.