1
|
|
|
<?php namespace Stevenmaguire\OAuth2\Client\Provider; |
2
|
|
|
|
3
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
4
|
|
|
|
5
|
|
|
class MicrosoftResourceOwner implements ResourceOwnerInterface |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Raw response |
9
|
|
|
* |
10
|
|
|
* @var array |
11
|
|
|
*/ |
12
|
|
|
protected $response; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Creates new resource owner. |
16
|
|
|
* |
17
|
|
|
* @param array $response |
18
|
|
|
*/ |
19
|
6 |
|
public function __construct(array $response = array()) |
20
|
|
|
{ |
21
|
6 |
|
$this->response = $response; |
22
|
6 |
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get user id |
26
|
|
|
* |
27
|
|
|
* @return string|null |
28
|
|
|
*/ |
29
|
|
|
public function getId() |
30
|
|
|
{ |
31
|
|
|
return $this->response['id'] ?: null; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get user email |
36
|
6 |
|
* |
37
|
|
|
* @return string|null |
38
|
6 |
|
*/ |
39
|
|
|
public function getEmail() |
40
|
|
|
{ |
41
|
|
|
return $this->response['mail'] ?: null; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get user principal name |
46
|
6 |
|
* |
47
|
|
|
* @return string|null |
48
|
6 |
|
*/ |
49
|
|
|
public function getPrincipalName() |
50
|
|
|
{ |
51
|
|
|
return $this->response['userPrincipalName'] ?: null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @deprecated will be removed in 3.0. Use getGivenName() instead. |
56
|
6 |
|
* |
57
|
|
|
* Get user first name |
58
|
6 |
|
* |
59
|
|
|
* @return string|null |
60
|
|
|
*/ |
61
|
|
|
public function getFirstname() |
62
|
|
|
{ |
63
|
|
|
return $this->getGivenName(); |
64
|
|
|
} |
65
|
|
|
|
66
|
6 |
|
/** |
67
|
|
|
* Get user given name (first name) |
68
|
6 |
|
* |
69
|
|
|
* @return string|null |
70
|
|
|
*/ |
71
|
|
|
public function getGivenName() |
72
|
|
|
{ |
73
|
|
|
return $this->response['givenName'] ?: null; |
74
|
|
|
} |
75
|
|
|
|
76
|
6 |
|
/** |
77
|
|
|
* @deprecated will be removed in 3.0. Use getSurname() instead. |
78
|
6 |
|
* |
79
|
|
|
* Get user lastname |
80
|
6 |
|
* |
81
|
|
|
* @return string|null |
82
|
|
|
*/ |
83
|
|
|
public function getLastname() |
84
|
|
|
{ |
85
|
|
|
return $this->getSurname(); |
86
|
|
|
} |
87
|
|
|
|
88
|
6 |
|
/** |
89
|
|
|
* Get user surname |
90
|
6 |
|
* |
91
|
|
|
* @return string|null |
92
|
|
|
*/ |
93
|
|
|
public function getSurname() |
94
|
|
|
{ |
95
|
|
|
return $this->response['surname'] ?: null; |
96
|
|
|
} |
97
|
|
|
|
98
|
6 |
|
/** |
99
|
|
|
* @deprecated will be removed in 3.0. Use getDisplayName() instead. |
100
|
6 |
|
* |
101
|
|
|
* Get user name |
102
|
|
|
* |
103
|
|
|
* @return string|null |
104
|
|
|
*/ |
105
|
|
|
public function getName() |
106
|
|
|
{ |
107
|
|
|
return $this->getDisplayName(); |
108
|
6 |
|
} |
109
|
|
|
|
110
|
6 |
|
/** |
111
|
|
|
* Get user name |
112
|
|
|
* |
113
|
|
|
* @return string|null |
114
|
|
|
*/ |
115
|
|
|
public function getDisplayName() |
116
|
|
|
{ |
117
|
|
|
return $this->response['displayName'] ?: null; |
118
|
3 |
|
} |
119
|
|
|
|
120
|
3 |
|
/** |
121
|
|
|
* @deprecated will be removed in 3.0. |
122
|
|
|
* |
123
|
|
|
* Get user urls |
124
|
|
|
* |
125
|
|
|
* @return string|null |
126
|
|
|
*/ |
127
|
|
|
public function getUrls() |
128
|
|
|
{ |
129
|
|
|
return null; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Return all of the owner details available as an array. |
134
|
|
|
* |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
|
|
public function toArray() |
138
|
|
|
{ |
139
|
|
|
return $this->response + [ |
140
|
|
|
'first_name' => $this->response['givenName'], |
141
|
|
|
'last_name' => $this->response['surname'], |
142
|
|
|
'name' => $this->response['displayName'], |
143
|
|
|
'link' => null |
144
|
|
|
]; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|