Skip to content
SESAME
Menu

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.

  1. Require the package.

    composer require waynestate/sesame
    

    Expected: waynestate/sesame is in composer.json and installed in vendor/.

  2. 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 Secure cookie travels only over https; browsers make an exception for http://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.

  3. Configure the fake driver for local development.

    use Waynestate\Sesame\Config;
    
    $config = Config::fromArray([
        'driver' => 'fake',
        'environment' => 'local',
        'fake' => [
            'username' => 'jdoe',
            'attributes' => ['cn' => ['John Doe']],
        ],
    ]);
    

    Expected: $config names the fake driver, the local environment, and the identity the driver will return.

  4. 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.

  5. 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 fake driver, that user is the one your resolver made from jdoe.

  6. 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#