oclockdev/keycloak-jwt-guard

A library to decode JWT provided by Keycloak

Installs: 300

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/oclockdev/keycloak-jwt-guard

v1.1.1 2023-04-11 09:09 UTC

README

A library to decode JWT provided by Keycloak

How to use?

<?php

use Oclockdev\KeycloakJwtGuard\Guard\KeycloakGuard;

require_once "./vendor/autoload.php";


// Get the bearer token from the request
$accessToken = $_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();