PHP code example of lyseontech / drupal-external-auth

1. Go to this page and download the library: Download lyseontech/drupal-external-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/ */

    

lyseontech / drupal-external-auth example snippets


$response = new Response();
$pdo = new PDO(...);

(new \DrupalExternalAuth\Auth($response, $pdo))->auth([
    'name'     => 'username',
    'pass'     => 'PrefixHash$' . 'hashOfPassord',
    'timezone' => 'America/Sao_Paulo',
    'langcode' => 'pt-br',
    'roles' => ['administrator']
]);

foreach ($response->headers->getCookies() as $cookie) {
    header('Set-Cookie: '.$cookie->getName().strstr($cookie, '='));
}

$response = new Response();
$pdo = new PDO(...);

(new \DrupalExternalAuth\Auth($response, $pdo))->logout();
foreach ($response->headers->getCookies() as $cookie) {
    header('Set-Cookie: '.$cookie->getName().strstr($cookie, '='));
}