-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSSODataTrait.php
More file actions
226 lines (204 loc) · 5.92 KB
/
SSODataTrait.php
File metadata and controls
226 lines (204 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
declare(strict_types=1);
/**
* SSO data implementation, based on this doc:
* https://developers.staffbase.com/guide/customplugin-overview
*
* PHP version 7.4
*
* @category Authentication
* @copyright 2017-2022 Staffbase, GmbH.
* @author Vitaliy Ivanov, Daniel Grosse
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://github.com/staffbase/plugins-sdk-php
*/
namespace Staffbase\plugins\sdk\SSOData;
/**
* A trait for the data transmitted from Staffbase app to a plugin
* using the Staffbase single-sign-on.
*/
trait SSODataTrait
{
use SharedDataTrait;
/**
* Get the branch id of the app that issued the token.
*
* @return null|string
*/
public function getBranchId(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_BRANCH_ID);
return is_string($value) ? $value : null;
}
/**
* Get the slug of the branch of the app that issued the token.
*
* @return null|string
*/
public function getBranchSlug(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_BRANCH_SLUG);
return is_string($value) ? $value : null;
}
/**
* Get the cipher of the session id for the session the token was issued.
*
* @return null|string
*/
public function getSessionId(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_SESSION_ID);
return is_string($value) ? $value : null;
}
/**
* Get the (plugin) instance id for which the token was issued.
*
* The id will always be present.
*
* @return null|string
*/
public function getInstanceId(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_INSTANCE_ID);
return is_string($value) ? $value : null;
}
/**
* Get the (plugin) instance name for which the token was issued.
*
* @return null|string
*/
public function getInstanceName(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_INSTANCE_NAME);
return is_string($value) ? $value : null;
}
/**
* Get the id of the authenticated user.
*
* @return null|string
*/
public function getUserId(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_USER_ID);
return is_string($value) ? $value : null;
}
/**
* Get the id of the user in an external system.
*
* Example use case would be to map user from an external store
* to the entry defined in the token.
*
* @return null|string
*/
public function getUserExternalId(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_USER_EXTERNAL_ID);
return is_string($value) ? $value : null;
}
/**
* Get the username of the user accessing.
*
* @return null|string
*/
public function getUserUsername(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_USER_USERNAME);
return is_string($value) ? $value : null;
}
/**
* Get the primary email address of the user accessing.
*
* @return null|string
*/
public function getUserPrimaryEmailAddress(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_USER_PRIMARY_EMAIL_ADDRESS);
return is_string($value) ? $value : null;
}
/**
* Get either the combined name of the user or the name of the token.
*
* @return null|string
*/
public function getFullName(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_USER_FULL_NAME);
return is_string($value) ? $value : null;
}
/**
* Get the first name of the user accessing.
*
* @return null|string
*/
public function getFirstName(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_USER_FIRST_NAME);
return is_string($value) ? $value : null;
}
/**
* Get the last name of the user accessing.
*
* @return null|string
*/
public function getLastName(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_USER_LAST_NAME);
return is_string($value) ? $value : null;
}
/**
* Get the type of the token.
*
* The type of the accessing entity can be either a "user" or a "token".
*
* @return null|string
*/
public function getType(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_ENTITY_TYPE);
return is_string($value) ? $value : null;
}
/**
* Get text color used in the overall theme for this audience.
*
* The color is represented as a CSS-HEX code.
*
* @return null|string
*/
public function getThemeTextColor(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_THEME_TEXT_COLOR);
return is_string($value) ? $value : null;
}
/**
* Get background color used in the overall theme for this audience.
*
* The color is represented as a CSS-HEX code.
*
* @return null|string
*/
public function getThemeBackgroundColor(): ?string
{
$value = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_THEME_BACKGROUND_COLOR);
return is_string($value) ? $value : null;
}
/**
* Get the locale of the requesting user in the format of language tags.
*
* @return string
*/
public function getLocale(): string
{
$val = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_USER_LOCALE);
return is_string($val) ? $val : '';
}
/**
* Get the user tags.
*
* @return array<mixed>|null
*/
public function getTags(): ?array
{
$val = $this->getClaimSafe(SSODataClaimsInterface::CLAIM_USER_TAGS);
return is_array($val) ? $val : null;
}
}