|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP version 7 |
|
4
|
|
|
* Application: directus_keycloak_client |
|
5
|
|
|
* |
|
6
|
|
|
* @category OAuth_2_Client_Library_Usage_For_Keycloak_With_Directus |
|
7
|
|
|
* @package Makuro\Directus\KeycloakClient\Provider |
|
8
|
|
|
* @author Eric Delaporte <[email protected]> |
|
9
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
|
10
|
|
|
* @link https://packagist.org/packages/makuro/directus_keycloak_client |
|
11
|
|
|
* Date: 19.11.19 |
|
12
|
|
|
* Time: 23:59 |
|
13
|
|
|
*/ |
|
14
|
|
|
namespace Makuro\Directus\KeycloakClient\Provider; |
|
15
|
|
|
|
|
16
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class KeycloakResourceOwner |
|
20
|
|
|
* |
|
21
|
|
|
* @category OAuth_2_Client_Library_Usage_For_Keycloak_With_Directus |
|
22
|
|
|
* @package Makuro\Directus\KeycloakClient\Provider |
|
23
|
|
|
* @author Eric Delaporte <[email protected]> |
|
24
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
|
25
|
|
|
* @link https://packagist.org/packages/makuro/directus_keycloak_client |
|
26
|
|
|
*/ |
|
27
|
|
|
class KeycloakResourceOwner implements ResourceOwnerInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Raw response |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $response; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Creates new resource owner. |
|
38
|
|
|
* |
|
39
|
|
|
* @param array $response response to be used later |
|
40
|
|
|
*/ |
|
41
|
2 |
|
public function __construct(array $response = []) |
|
42
|
|
|
{ |
|
43
|
2 |
|
$this->response = $response; |
|
44
|
2 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get resource owner id |
|
48
|
|
|
* |
|
49
|
|
|
* @return string|null |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function getId() |
|
52
|
|
|
{ |
|
53
|
2 |
|
return $this->response['sub'] ?: null; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get resource owner email |
|
58
|
|
|
* |
|
59
|
|
|
* @return string|null |
|
60
|
|
|
*/ |
|
61
|
2 |
|
public function getEmail() |
|
62
|
|
|
{ |
|
63
|
2 |
|
return $this->response['email'] ?: null; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get resource owner name |
|
68
|
|
|
* |
|
69
|
|
|
* @return string|null |
|
70
|
|
|
*/ |
|
71
|
2 |
|
public function getName() |
|
72
|
|
|
{ |
|
73
|
2 |
|
return $this->response['name'] ?: null; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Return all of the owner details available as an array. |
|
78
|
|
|
* |
|
79
|
|
|
* @return array |
|
80
|
|
|
*/ |
|
81
|
2 |
|
public function toArray() |
|
82
|
|
|
{ |
|
83
|
2 |
|
return $this->response; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|