Skip to content

Commit

Permalink
Added auth client for keycloak
Browse files Browse the repository at this point in the history
  • Loading branch information
eluhr committed Feb 9, 2024
1 parent 7b8e192 commit da59707
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/User/AuthClient/Keycloak.php
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit da59707

Please sign in to comment.