Skip to content

Commit d27d515

Browse files
Merge pull request #20 from Staffbase/cctech-added-email-username-to-ssodata
(Updated) Added username and primary email address to SSO token data
2 parents 391ec35 + 15bd323 commit d27d515

5 files changed

Lines changed: 127 additions & 26 deletions

File tree

AUTHORS.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Authors ordered by first contribution
22

33
Vitaliy Ivanov - https://github.com/viviivanov
4-
Stefan Staude - https://github.com/staust
4+
Stefan Staude - https://github.com/staust
5+
Max Scholz - https://github.com/maximizeIT

doc/api.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* [getInstanceName](#getinstancename)
1313
* [getUserId](#getuserid)
1414
* [getUserExternalId](#getuserexternalid)
15+
* [getUserUsername](#getuserusername)
16+
* [getUserPrimaryEmailAddress](#getuserprimaryemailaddress)
1517
* [getFullName](#getfullname)
1618
* [getFirstName](#getfirstname)
1719
* [getLastName](#getlastname)
@@ -43,6 +45,8 @@
4345
* [getInstanceName](#getinstancename-1)
4446
* [getUserId](#getuserid-1)
4547
* [getUserExternalId](#getuserexternalid-1)
48+
* [getUserUsername](#getuserusername-1)
49+
* [getUserPrimaryEmailAddress](#getuserprimaryemailaddress-1)
4650
* [getFullName](#getfullname-1)
4751
* [getFirstName](#getfirstname-1)
4852
* [getLastName](#getlastname-1)
@@ -211,6 +215,38 @@ to the entry defined in the token.
211215

212216

213217

218+
---
219+
220+
### getUserUsername
221+
222+
Get the username of the user accessing.
223+
224+
```php
225+
PluginSession::getUserUsername( ): null|string
226+
```
227+
228+
229+
230+
231+
232+
233+
234+
---
235+
236+
### getUserPrimaryEmailAddress
237+
238+
Get the primary email address of the user accessing.
239+
240+
```php
241+
PluginSession::getUserPrimaryEmailAddress( ): null|string
242+
```
243+
244+
245+
246+
247+
248+
249+
214250
---
215251

216252
### getFullName
@@ -734,6 +770,36 @@ to the entry defined in the token.
734770

735771

736772

773+
---
774+
775+
### getUserUsername
776+
777+
Get the username of the user accessing.
778+
779+
```php
780+
SSOToken::getUserUsername( ): null|string
781+
```
782+
783+
784+
785+
786+
787+
788+
---
789+
790+
### getUserPrimaryEmailAddress
791+
792+
Get the primary email address of the user accessing.
793+
794+
```php
795+
SSOToken::getUserPrimaryEmailAddress( ): null|string
796+
```
797+
798+
799+
800+
801+
802+
737803
---
738804

739805
### getFullName

src/SSOData.php

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22
/**
33
* SSO data implementation, based on this doc:
4-
* https://developers.staffbase.com/api/plugin-sso/
4+
* https://developers.staffbase.com/guide/customplugin-overview
55
*
66
* PHP version 5.5.9
77
*
88
* @category Authentication
9-
* @copyright 2017-2019 Staffbase, GmbH.
9+
* @copyright 2017-2020 Staffbase, GmbH.
1010
* @author Vitaliy Ivanov
1111
* @license http://www.apache.org/licenses/LICENSE-2.0
1212
* @link https://github.com/staffbase/plugins-sdk-php
@@ -20,27 +20,29 @@
2020
*/
2121
abstract class SSOData
2222
{
23-
const CLAIM_AUDIENCE = 'aud';
24-
const CLAIM_EXPIRE_AT = 'exp';
25-
const CLAIM_NOT_BEFORE = 'nbf';
26-
const CLAIM_ISSUED_AT = 'iat';
27-
const CLAIM_ISSUER = 'iss';
28-
const CLAIM_SESSION_ID = 'sid';
29-
const CLAIM_INSTANCE_ID = 'instance_id';
30-
const CLAIM_INSTANCE_NAME = 'instance_name';
31-
const CLAIM_BRANCH_ID = 'branch_id';
32-
const CLAIM_BRANCH_SLUG = 'branch_slug';
33-
const CLAIM_USER_ID = 'sub';
34-
const CLAIM_USER_EXTERNAL_ID = 'external_id';
35-
const CLAIM_USER_FULL_NAME = 'name';
36-
const CLAIM_USER_FIRST_NAME = 'given_name';
37-
const CLAIM_USER_LAST_NAME = 'family_name';
38-
const CLAIM_USER_ROLE = 'role';
39-
const CLAIM_ENTITY_TYPE = 'type';
40-
const CLAIM_THEME_TEXT_COLOR = 'theming_text';
41-
const CLAIM_THEME_BACKGROUND_COLOR = 'theming_bg';
42-
const CLAIM_USER_LOCALE = 'locale';
43-
const CLAIM_USER_TAGS = 'tags';
23+
const CLAIM_AUDIENCE = 'aud';
24+
const CLAIM_EXPIRE_AT = 'exp';
25+
const CLAIM_NOT_BEFORE = 'nbf';
26+
const CLAIM_ISSUED_AT = 'iat';
27+
const CLAIM_ISSUER = 'iss';
28+
const CLAIM_SESSION_ID = 'sid';
29+
const CLAIM_INSTANCE_ID = 'instance_id';
30+
const CLAIM_INSTANCE_NAME = 'instance_name';
31+
const CLAIM_BRANCH_ID = 'branch_id';
32+
const CLAIM_BRANCH_SLUG = 'branch_slug';
33+
const CLAIM_USER_ID = 'sub';
34+
const CLAIM_USER_EXTERNAL_ID = 'external_id';
35+
const CLAIM_USER_USERNAME = 'username';
36+
const CLAIM_USER_PRIMARY_EMAIL_ADDRESS = 'primary_email_address';
37+
const CLAIM_USER_FULL_NAME = 'name';
38+
const CLAIM_USER_FIRST_NAME = 'given_name';
39+
const CLAIM_USER_LAST_NAME = 'family_name';
40+
const CLAIM_USER_ROLE = 'role';
41+
const CLAIM_ENTITY_TYPE = 'type';
42+
const CLAIM_THEME_TEXT_COLOR = 'theming_text';
43+
const CLAIM_THEME_BACKGROUND_COLOR = 'theming_bg';
44+
const CLAIM_USER_LOCALE = 'locale';
45+
const CLAIM_USER_TAGS = 'tags';
4446

4547
const USER_ROLE_EDITOR = 'editor';
4648

@@ -217,6 +219,26 @@ public function getUserExternalId() {
217219
return $this->getClaimSafe(self::CLAIM_USER_EXTERNAL_ID);
218220
}
219221

222+
/**
223+
* Get the username of the user accessing.
224+
*
225+
* @return null|string
226+
*/
227+
public function getUserUsername() {
228+
229+
return $this->getClaimSafe(self::CLAIM_USER_USERNAME);
230+
}
231+
232+
/**
233+
* Get the primary email address of the user accessing.
234+
*
235+
* @return null|string
236+
*/
237+
public function getUserPrimaryEmailAddress() {
238+
239+
return $this->getClaimSafe(self::CLAIM_USER_PRIMARY_EMAIL_ADDRESS);
240+
}
241+
220242
/**
221243
* Get either the combined name of the user or the name of the token.
222244
*

test/SSODataTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* SSO data Test implementation, based on this doc:
4-
* https://developers.staffbase.com/api/plugin-sso/
4+
* https://developers.staffbase.com/guide/customplugin-overview
55
*
66
* PHP version 5.5.9
77
*
@@ -44,6 +44,8 @@ public static function getTokenData()
4444
$tokenData[SSOData::CLAIM_INSTANCE_NAME] = 'Our locations';
4545
$tokenData[SSOData::CLAIM_USER_ID] = '541954c3e4b08bbdce1a340a';
4646
$tokenData[SSOData::CLAIM_USER_EXTERNAL_ID] = 'jdoe';
47+
$tokenData[SSOData::CLAIM_USER_USERNAME] = 'john.doe';
48+
$tokenData[SSOData::CLAIM_USER_PRIMARY_EMAIL_ADDRESS] = 'jdoe@email.com';
4749
$tokenData[SSOData::CLAIM_USER_FULL_NAME] = 'John Doe';
4850
$tokenData[SSOData::CLAIM_USER_FIRST_NAME] = 'John';
4951
$tokenData[SSOData::CLAIM_USER_LAST_NAME] = 'Doe';
@@ -79,6 +81,8 @@ public static function getTokenAccesors()
7981
$accessors[SSOData::CLAIM_INSTANCE_NAME] = 'getInstanceName';
8082
$accessors[SSOData::CLAIM_USER_ID] = 'getUserId';
8183
$accessors[SSOData::CLAIM_USER_EXTERNAL_ID] = 'getUserExternalId';
84+
$accessors[SSOData::CLAIM_USER_USERNAME] = 'getUserUsername';
85+
$accessors[SSOData::CLAIM_USER_PRIMARY_EMAIL_ADDRESS] = 'getUserPrimaryEmailAddress';
8286
$accessors[SSOData::CLAIM_USER_FULL_NAME] = 'getFullName';
8387
$accessors[SSOData::CLAIM_USER_FIRST_NAME] = 'getFirstName';
8488
$accessors[SSOData::CLAIM_USER_LAST_NAME] = 'getLastName';
@@ -109,6 +113,8 @@ public static function getTokenAccesors()
109113
* @covers \Staffbase\plugins\sdk\SSOData::getInstanceName()
110114
* @covers \Staffbase\plugins\sdk\SSOData::getUserId()
111115
* @covers \Staffbase\plugins\sdk\SSOData::getUserExternalId()
116+
* @covers \Staffbase\plugins\sdk\SSOData::getUserUsername()
117+
* @covers \Staffbase\plugins\sdk\SSOData::getUserPrimaryEmailAddress()
112118
* @covers \Staffbase\plugins\sdk\SSOData::getFullName()
113119
* @covers \Staffbase\plugins\sdk\SSOData::getFirstName()
114120
* @covers \Staffbase\plugins\sdk\SSOData::getLastName()

test/SSOTokenTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* SSO token Test implementation, based on this doc:
4-
* https://developers.staffbase.com/api/plugin-sso/
4+
* https://developers.staffbase.com/guide/customplugin-overview
55
*
66
* PHP version 5.5.9
77
*
@@ -73,6 +73,8 @@ public static function createSignedTokenFromData($privateKey, $tokenData) {
7373
->withClaim(SSOToken::CLAIM_INSTANCE_ID, $tokenData[SSOToken::CLAIM_INSTANCE_ID])
7474
->withClaim(SSOToken::CLAIM_INSTANCE_NAME, $tokenData[SSOToken::CLAIM_INSTANCE_NAME])
7575
->withClaim(SSOToken::CLAIM_USER_EXTERNAL_ID, $tokenData[SSOToken::CLAIM_USER_EXTERNAL_ID])
76+
->withClaim(SSOToken::CLAIM_USER_USERNAME, $tokenData[SSOToken::CLAIM_USER_USERNAME])
77+
->withClaim(SSOToken::CLAIM_USER_PRIMARY_EMAIL_ADDRESS, $tokenData[SSOToken::CLAIM_USER_PRIMARY_EMAIL_ADDRESS])
7678
->withClaim(SSOToken::CLAIM_USER_FULL_NAME, $tokenData[SSOToken::CLAIM_USER_FULL_NAME])
7779
->withClaim(SSOToken::CLAIM_USER_FIRST_NAME, $tokenData[SSOToken::CLAIM_USER_FIRST_NAME])
7880
->withClaim(SSOToken::CLAIM_USER_LAST_NAME, $tokenData[SSOToken::CLAIM_USER_LAST_NAME])
@@ -109,6 +111,8 @@ private static function createUnsignedTokenFromData($tokenData) {
109111
->withClaim(SSOToken::CLAIM_INSTANCE_ID, $tokenData[SSOToken::CLAIM_INSTANCE_ID])
110112
->withClaim(SSOToken::CLAIM_INSTANCE_NAME, $tokenData[SSOToken::CLAIM_INSTANCE_NAME])
111113
->withClaim(SSOToken::CLAIM_USER_EXTERNAL_ID, $tokenData[SSOToken::CLAIM_USER_EXTERNAL_ID])
114+
->withClaim(SSOToken::CLAIM_USER_USERNAME, $tokenData[SSOToken::CLAIM_USER_USERNAME])
115+
->withClaim(SSOToken::CLAIM_USER_PRIMARY_EMAIL_ADDRESS, $tokenData[SSOToken::CLAIM_USER_PRIMARY_EMAIL_ADDRESS])
112116
->withClaim(SSOToken::CLAIM_USER_FULL_NAME, $tokenData[SSOToken::CLAIM_USER_FULL_NAME])
113117
->withClaim(SSOToken::CLAIM_USER_FIRST_NAME, $tokenData[SSOToken::CLAIM_USER_FIRST_NAME])
114118
->withClaim(SSOToken::CLAIM_USER_LAST_NAME, $tokenData[SSOToken::CLAIM_USER_LAST_NAME])
@@ -321,6 +325,8 @@ public function testConstructorToFailOnUnsignedToken() {
321325
* @covers \Staffbase\plugins\sdk\SSOToken::getInstanceName()
322326
* @covers \Staffbase\plugins\sdk\SSOToken::getUserId()
323327
* @covers \Staffbase\plugins\sdk\SSOToken::getUserExternalId()
328+
* @covers \Staffbase\plugins\sdk\SSOToken::getUserUsername()
329+
* @covers \Staffbase\plugins\sdk\SSOToken::getUserPrimaryEmailAddress()
324330
* @covers \Staffbase\plugins\sdk\SSOToken::getFullName()
325331
* @covers \Staffbase\plugins\sdk\SSOToken::getFirstName()
326332
* @covers \Staffbase\plugins\sdk\SSOToken::getLastName()

0 commit comments

Comments
 (0)