PHP code example of caridea / auth

1. Go to this page and download the library: Download caridea/auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

caridea / auth example snippets


// Let's say $session is a \Caridea\Session\Session, such as \Caridea\Session\NativeSession
// Let's say $publisher is a \Caridea\Event\Publisher, such as \Caridea\Container\Objects
$service = new \Caridea\Auth\Service($session, $publisher);

// Let's say $collection is a \MongoCollection
$adapter = new \Caridea\Auth\Adapter\Mongo($collection, 'username', 'password');

// Let's say $request is a \Psr\Http\Message\RequestInterface
if ($service->login($request, $adapter)) {
    $principal = $service->getPrincipal();
    $username = $principal->getUsername();
    $details = $principal->getDetails());

    // $details = [
    //    'id' => '1234567890',
    //    'ua' => 'Mozilla/5.0',
    //    'ip' => '192.168.1.1'
    // ];
}

// Let's say $session is a \Caridea\Session\Session, such as \Caridea\Session\NativeSession
// Let's say $publisher is a \Caridea\Event\Publisher, such as \Caridea\Container\Objects
$service = new \Caridea\Auth\Service($session, $publisher);

if ($service->resume()) {
    $principal = $service->getPrincipal();
}

// Let's say $session is a \Caridea\Session\Session, such as \Caridea\Session\NativeSession
// Let's say $publisher is a \Caridea\Event\Publisher, such as \Caridea\Container\Objects
$service = new \Caridea\Auth\Service($session, $publisher);

// Let's say $collection is a \MongoCollection
$adapter = new \Caridea\Auth\Adapter\Mongo($collection, 'username', 'password');

if ($service->logout()) {
    // anonymous!
}