From da59707f3854fb533ab7ff9001bade01b2958f87 Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Fri, 9 Feb 2024 14:26:13 +0100 Subject: [PATCH 1/5] Added auth client for keycloak --- src/User/AuthClient/Keycloak.php | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/User/AuthClient/Keycloak.php diff --git a/src/User/AuthClient/Keycloak.php b/src/User/AuthClient/Keycloak.php new file mode 100644 index 0000000..42a3cd7 --- /dev/null +++ b/src/User/AuthClient/Keycloak.php @@ -0,0 +1,35 @@ +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; + } +} From 5e697e2ad503398aedad8d7efa5c2c0c9c9e02af Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Fri, 9 Feb 2024 14:27:32 +0100 Subject: [PATCH 2/5] Added Keycloak as one of the supported clients in the docs --- docs/guides/social-network-authentication.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/guides/social-network-authentication.md b/docs/guides/social-network-authentication.md index b8d927a..9a51802 100644 --- a/docs/guides/social-network-authentication.md +++ b/docs/guides/social-network-authentication.md @@ -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` From 6056be8f86beec357842f8ffe5a76be7bfa42e7e Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Fri, 9 Feb 2024 14:28:16 +0100 Subject: [PATCH 3/5] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3dd607..65e1d17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## dev +- Enh: Keycloak auth client (e.luhr) - Fix: Social Network Auth (eluhr) ## 1.6.2 Jan 4th, 2024 From 888bc4c0e5f834f081ecdad33b42b8f6e80e0521 Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Fri, 9 Feb 2024 14:43:51 +0100 Subject: [PATCH 4/5] Added configuration example in keycloak auth client --- src/User/AuthClient/Keycloak.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/User/AuthClient/Keycloak.php b/src/User/AuthClient/Keycloak.php index 42a3cd7..5246383 100644 --- a/src/User/AuthClient/Keycloak.php +++ b/src/User/AuthClient/Keycloak.php @@ -5,6 +5,26 @@ namespace Da\User\AuthClient; use Da\User\Contracts\AuthClientInterface; use yii\authclient\OpenIdConnect; +/** + * Example application configuration: + * + * ```php + * 'components' => [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'github' => [ + * '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 { /** From a6e249291b7a641a107318ce70507fa483969c57 Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Fri, 9 Feb 2024 14:45:15 +0100 Subject: [PATCH 5/5] copy & paste fix --- src/User/AuthClient/Keycloak.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/User/AuthClient/Keycloak.php b/src/User/AuthClient/Keycloak.php index 5246383..78943dc 100644 --- a/src/User/AuthClient/Keycloak.php +++ b/src/User/AuthClient/Keycloak.php @@ -13,7 +13,7 @@ use yii\authclient\OpenIdConnect; * 'authClientCollection' => [ * 'class' => 'yii\authclient\Collection', * 'clients' => [ - * 'github' => [ + * 'keycloak' => [ * 'class' => 'yii\authclient\clients\Keycloak', * 'clientId' => 'keycloak_client_id', * 'clientSecret' => 'keycloak_client_secret',