Skip to content

Koricz/keycloak-adapter-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keycloak PHP adapter

Latest Stable Version Total Downloads License Monthly Downloads

Install

composer require ataccama/keycloak-adapter

Neon config:

parameters:
    keycloak:
        realmId: your_realm
        clientDd: your_client_id
        host: https://your.keycloak.com
        defaultRedirectUri: https://your.default.url
        api:
            username: your_username
            password: your_password
            clientId: your_api_client_id
            clientSecret: your_client_secret
            
services:
    - Ataccama\Adapters\Keycloak(%keycloak%)

Use

Create new class and extend class Ataccama\Auth, then you MUST implement all missing methods with your own logic.

Login URL: $loginUrl = $yourAuthClass->getLoginUrl()

In code use your class like this: $yourAuthClass->authorize($_GET['code'])

Example (Nette Framework):

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

About

Connect php application with Keycloak.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%