PHP code example of stolfam / keycloak-adapter-php

1. Go to this page and download the library: Download stolfam/keycloak-adapter-php 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/ */

    

stolfam / keycloak-adapter-php example snippets


// waiting for authorization code from Keycloak
if ($yourAuthClass->authorize($this->getParameter('code'))) {
    $this->redirectUrl($yourAuthClass->getRedirectUri());
} else {
    if (!$yourAuthClass->isAuthorized()) {
        $this->redirectUrl($yourAuthClass->getLoginUrl());
    }
}

// check if user is logged in on every page, if not redirect him to Keycloak login page
if (!$yourAuthClass->isAuthorized()) {
    $this->redirectUrl($yourAuthClass->getLoginUrl());
}