PHP code example of ataccama / keycloak-adapter

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

    

ataccama / keycloak-adapter 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());
}