PHP code example of oclockdev / keycloak-jwt-guard

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

    

oclockdev / keycloak-jwt-guard example snippets





use Oclockdev\KeycloakJwtGuard\Guard\KeycloakGuard;

SERVER['HTTP_AUTHORIZATION'];

// Create a new instance of KeycloakGuard with Keycloak server info
$keycloakGuard = new KeycloakGuard([
    "serverUrl" => "https://localhost:8080",
    "realm"     => "master",
    "accessToken" => $accessToken
]);

// Authenticate with the access token and return the JWT payload
$payload = $keycloakGuard->authenticate();

// Call the userinfo keycloak endpoint with the access token
$userinfo = $keycloakGuard->getOwnerRessource();