Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Keycloak as a new Auth Client #537

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## dev

- Enh: Keycloak auth client (e.luhr)
- Fix: Social Network Auth (eluhr)

## 1.6.2 Jan 4th, 2024
Expand Down
1 change: 1 addition & 0 deletions docs/guides/social-network-authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The following is the list of clients supported by the module:
- **Facebook** - `Da\User\AuthClient\Facebook`
- **Github** - `Da\User\AuthClient\Github`
- **Google** - `Da\User\AuthClient\Google`
- **Keycloak** - `Da\User\AuthClient\Keycloak`
- **LinkedIn** - `Da\User\AuthClient\LinkedIn`
- **Twitter** - `Da\User\AuthClient\Twitter`
- **VKontakte** - `Da\User\AuthClient\VKontakte`
Expand Down
55 changes: 55 additions & 0 deletions src/User/AuthClient/Keycloak.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Da\User\AuthClient;

use Da\User\Contracts\AuthClientInterface;
use yii\authclient\OpenIdConnect;

/**
* Example application configuration:
*
* ```php
* 'components' => [
* 'authClientCollection' => [
* 'class' => 'yii\authclient\Collection',
* 'clients' => [
* 'keycloak' => [
* 'class' => 'yii\authclient\clients\Keycloak',
* 'clientId' => 'keycloak_client_id',
* 'clientSecret' => 'keycloak_client_secret',
* 'issuerUrl' => 'http://keycloak/realms/your-realm',
* ],
* ],
* ]
* // ...
* ]
* ```
*/
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;
}
}
Loading