Added auth client for keycloak

This commit is contained in:
Elias Luhr
2024-02-09 14:26:13 +01:00
parent 7b8e192686
commit da59707f38

View File

@ -0,0 +1,35 @@
<?php
namespace Da\User\AuthClient;
use Da\User\Contracts\AuthClientInterface;
use yii\authclient\OpenIdConnect;
class Keycloak extends OpenIdConnect implements AuthClientInterface
{
/**
* {@inheritdoc}
*/
public function getEmail()
{
// claim from email scope
return $this->getUserAttributes()['email'] ?? null;
}
/**
* {@inheritdoc}
*/
public function getUserName()
{
// claim from profile scope
return $this->getUserAttributes()['preferred_username'] ?? $this->getEmail();
}
/**
* {@inheritdoc}
*/
public function getUserId()
{
return $this->getUserAttributes()['sub'] ?? null;
}
}