Quick start#
The shortest walk through the door: a framework-free PHP page and the fake
driver, which needs no server and no registration. Every snippet below is the
Raw PHP example, one move at a time.
-
Require the package.
composer require waynestate/sesameExpected:
waynestate/sesameis incomposer.jsonand installed invendor/. -
Start the session. The app owns the session; SESAME never starts one.
<?php declare(strict_types=1); require __DIR__.'/vendor/autoload.php'; // Or call helmet_boot(), which sets all of this. NativeSession warns without it. ini_set('session.use_strict_mode', '1'); session_set_cookie_params(['httponly' => true, 'secure' => true, 'samesite' => 'Lax']); session_start();A
Securecookie travels only over https; browsers make an exception forhttp://localhost, so the fake driver still works there.Expected: the session is started, the autoload file sees the package, and the PHP error log has no
SESAME:warning about the session settings or the cookie flags. -
Configure the
fakedriver for local development.use Waynestate\Sesame\Config; $config = Config::fromArray([ 'driver' => 'fake', 'environment' => 'local', 'fake' => [ 'username' => 'jdoe', 'attributes' => ['cn' => ['John Doe']], ], ]);Expected:
$confignames thefakedriver, the local environment, and the identity the driver will return. -
Build the facade and hand it to the functions.
use Waynestate\Sesame\DriverFactory; use Waynestate\Sesame\Identity; use Waynestate\Sesame\Sesame; use Waynestate\Sesame\Session\NativeSession; use Waynestate\Sesame\UserResolver; $sesame = new Sesame( DriverFactory::make($config), new class implements UserResolver { public function findOrImportUser(Identity $identity): mixed { return $identity->username; } }, new NativeSession(), $config, ); sesame($sesame);Expected: no output. The next call has a driver, a resolver, a session and a config to work with.
-
Sign the user in.
$user = sesame_login();Expected: when the login has not completed, SESAME sends the redirect to the identity provider and stops the script; when a ticket completes it, it sends the redirect to the driver's service URL and stops the script, so the ticket never stays in the address bar; when the user is already signed in and the request has no ticket, it returns the user. With the
fakedriver, that user is the one your resolver made fromjdoe. -
Read the user on a protected page.
$user = sesame_user();Expected: the user the login stored in the session.
What you built#
A framework-free PHP page that signs a user in through SESAME and reads the signed-in user back out of the session. The protocol never held the session: you started it and you read it, and switching driver is a config change with no code change.
Next steps#
- Which driver for my app?: pick the key for your real door.
- Raw PHP: the whole example, with every piece named.
- Laravel: the same door in a Laravel app.
- Session timeouts: the two clocks every session runs on.