-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #537 from dmstr-forks/master
Added Keycloak as a new Auth Client
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
## dev | ||
|
||
- Enh: Keycloak auth client (e.luhr) | ||
- Fix: Social Network Auth (eluhr) | ||
|
||
## 1.6.2 Jan 4th, 2024 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |