Two-Phase SSO Rollout: Keep the Dependency Upgrade Separate

· 4 min read

The problem: one PR that does too much

Adding SSO to a Laravel app sounds like a single piece of work. In practice it turned out to be two things tangled together: upgrading a shared library that half the app already relied on, and adding a whole new authentication flow. If I'd bundled both into one pull request, a reviewer couldn't tell which change broke what, and rolling back would mean losing either both or neither.

The shared library was a JWT package. The SSO package I was wiring in needed major version 7 of it, but the app was pinned to version 6 by two other packages that handled completely unrelated things — Google Calendar sync and spreadsheet exports. Those features have their own test suites. Any regression in them has nothing to do with the sign-in flow I was building, but in a combined diff it would look like it does.

The fix was to split the work into two commits on the same feature branch, with a clear contract between them: Phase 1 is the library upgrade and nothing else. Phase 2 is all the SSO code, and both feature switches start off.

Phase 1: the library upgrade, nothing else

The first commit changes composer.json and nothing else. No new routes, no new middleware, no config files for the new feature.

"require": {
    "shared/jwt-lib": "^7.0",
    "vendor/google-client": "^2.20",
    "vendor/google-auth": "^1.55"
}

After composer update -W, I went through every class and method the existing code called on the upgraded packages and confirmed they still existed in the new versions. Then I ran the existing test suite. The goal was a green run with no new code, so a reviewer can look at this commit and ask exactly one question: did the library upgrade break anything we already had?

For tests that need a real external service and can't run in CI, I noted them explicitly in the commit message: "Manual check required: test X and Y in a browser before releasing." That's honest. Pretending the upgrade is fully tested when it isn't makes the split pointless.

Phase 2: all the SSO code, both switches off

The second commit adds everything the new feature needs — config, middleware, routes, controller, tests — but the feature is off by default:

// config/sso.php
return [
    'enabled' => env('SSO_ENABLED', false),  // show the sign-in button
    'enforce' => env('SSO_ENFORCE', false),  // remove password login entirely
];

The middleware checks the flag before doing anything:

// app/Http/Middleware/SsoSession.php
public function handle(Request $request, Closure $next): Response
{
    if (!config('sso.enabled')) {
        return $next($request);
    }

    // ... hub session-check logic
}

Both test configs pin the flags to false, regardless of what a developer's local .env says:

<!-- phpunit.xml -->
<env name="SSO_ENABLED" value="false"/>
<env name="SSO_ENFORCE" value="false"/>

That last part matters. If a developer has SSO_ENABLED=true locally, the test suite still runs against the old flow. A failing test means something actually broke, not "SSO happens to be on in this environment."

The SSO tests themselves use Http::fake to simulate the external auth hub, so no request leaves the machine:

Http::fake([
    'auth.example.com/token' => Http::response(['access_token' => 'fake-token'], 200),
    'auth.example.com/userinfo' => Http::response([
        'sub'   => 'google-uid-123',
        'email' => '[email protected]',
    ], 200),
]);

When this commit lands on the production server, nothing changes for anyone. The SSO code is sitting there, fully tested, ready to turn on with one environment variable.

Why the split helps at review time

With the two commits separated, the review conversation is cleaner:

  • Phase 1 is composer.json, composer.lock, and no PHP changes. A reviewer checks whether the library versions are compatible and whether the existing tests still pass.
  • Phase 2 is new PHP files and no version changes. A reviewer checks the authentication logic, middleware ordering, and test coverage.

Mixing them produces a diff where a Composer lock file change, five new middleware files, three new routes, and a modified login controller all appear together. It's not unreadable, but the question "did the library upgrade break Calendar sync?" gets buried inside "how does the token exchange work?"

Reverting follows the same logic. If Phase 1 goes to production and something breaks in an existing feature, the revert is one commit and doesn't touch any SSO code. If Phase 2 goes live and the authentication flow has a problem, flipping SSO_ENABLED=false in .env and running config:clear is enough — no git operations needed at all.

What I'd do differently

The one thing I underestimated was how long it takes to verify the parts of the library upgrade that can't run in CI. I noted the manual checks in my planning docs, but docs don't travel with the commit. Next time I'd put those notes directly in the commit message: a short list of exactly which browser-tested paths need a human to click through before the commit goes to production. That way the information is attached to the work, not to a separate document that someone might not read.

Beyond that, the pattern generalises to any situation where a new feature forces a dependency upgrade. The upgrade is mechanical and boring; the feature is interesting and risky. Keep the boring stuff in its own commit, ship it, verify the existing behaviour, then come back for the interesting part.

  • #sso
  • #laravel
  • #php
  • #feature-flags
  • #composer

Written by Ryan Yovanda