Skip to content

Commit 6aefe62

Browse files
author
Max Scholz
committed
Added username and primary email address to SSO token data
1 parent 9c37069 commit 6aefe62

8 files changed

Lines changed: 48 additions & 18 deletions

File tree

README.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
[![Build Status](https://travis-ci.org/Staffbase/plugins-sdk-nodejs.svg?branch=master)](https://travis-ci.org/Staffbase/plugins-sdk-nodejs)
2-
31
# Staffbase Plugins SDK for Node.js.
42

53
If you are developing your own plugin for your Staffbase app we describe the authentication flow of a plugin at https://developers.staffbase.com/api/plugin-sso/. While this documentation just covers the conceptual ideas of the interface of plugins though – the so called Plugin SSO – we want to provide a library to help you develop your first plugin for Staffbase even faster. This SDK provides the basic functionality to parse and verify a provided token for Node.js.
@@ -87,6 +85,8 @@ The following data can be retrieved from the token:
8785
|CLAIM_INSTANCE_NAME|instance_name|getInstanceName()|Get the (plugin) instance name for which the token was issued.|
8886
|CLAIM_USER_ID|sub|getUserId()|Get the id of the authenticated user.|
8987
|CLAIM_USER_EXTERNAL_ID|external_id|getUserExternalId()|Get the id of the user in an external system.|
88+
|CLAIM_USER_USERNAME|username|getUserUsername()|Get the username of the user accessing.|
89+
|CLAIM_USER_PRIMARY_EMAIL_ADDRESS|primary_email_address|getUserPrimaryEmailAddress()|Get the primary email address of the user accessing.|
9090
|CLAIM_USER_FULL_NAME|name|getFullName()|Get either the combined name of the user or the name of the token.|
9191
|CLAIM_USER_FIRST_NAME|given_name|getFirstName()|Get the first name of the user accessing.|
9292
|CLAIM_USER_LAST_NAME|family_name|getLastName()|Get the last name of the user accessing.|

docSrc/sections/usage.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ The following data can be retrieved from the token:
6363
|CLAIM_INSTANCE_NAME|instance_name|getInstanceName()|Get the (plugin) instance name for which the token was issued.|
6464
|CLAIM_USER_ID|sub|getUserId()|Get the id of the authenticated user.|
6565
|CLAIM_USER_EXTERNAL_ID|external_id|getUserExternalId()|Get the id of the user in an external system.|
66+
|CLAIM_USER_USERNAME|username|getUserUsername()|Get the username of the user accessing.|
67+
|CLAIM_USER_PRIMARY_EMAIL_ADDRESS|primary_email_address|getUserPrimaryEmailAddress()|Get the primary email address of the user accessing.|
6668
|CLAIM_USER_FULL_NAME|name|getFullName()|Get either the combined name of the user or the name of the token.|
6769
|CLAIM_USER_FIRST_NAME|given_name|getFirstName()|Get the first name of the user accessing.|
6870
|CLAIM_USER_LAST_NAME|family_name|getLastName()|Get the last name of the user accessing.|

docs/API.MD

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
11

2-
## Classes
3-
Global | Description
4-
------ | -----------
5-
SSOToken | SSOToken Class. Used as an interface to decode the Staffbase SSO Token.
6-
SSOTokenData : SSOTokenData | SSOTokenData Class used to host the token data values and provide getter functions to extract correspinding values.
7-
8-
## Functions
9-
Global | Description
10-
------ | -----------
11-
ssoMiddleWare(secret, audience) ⇒ function | Mountable express middleware functions
12-
readKeyFile(path, cb) ⇒ String | Reads public key file from the specified path and returns a string representation
13-
of the key to be used to decode token.
14-
asCert(cert, type) ⇒ string | asCert converts a binary encoded key to PKCS8 format
15-
isPKCS8Format(key, type) ⇒ Boolean | Checks if the format of the key is similar to PKCS8 Format.
16-
transformKeyToFormat(key, type) ⇒ String | Transforms the provided key to PKCS8 format for supported jwt algorithm.
17-
182
## SSOToken
193
SSOToken Class. Used as an interface to decode the Staffbase SSO Token.
204

@@ -60,6 +44,8 @@ SSOTokenData Class used to host the token data values and provide getter functio
6044
* [.getInstanceName()](#markdown-header-ssotokendatagetinstancename-nullstring) ⇒ null ⎮ string
6145
* [.getUserId()](#markdown-header-ssotokendatagetuserid-nullstring) ⇒ null ⎮ string
6246
* [.getUserExternalId()](#markdown-header-ssotokendatagetuserexternalid-nullstring) ⇒ null ⎮ string
47+
* [.getUserUsername()](#markdown-header-ssotokendatagetuserusername-nullstring) ⇒ null ⎮ string
48+
* [.getUserPrimaryEmailAddress()](#markdown-header-ssotokendatagetuserprimaryemailaddress-nullstring) ⇒ null ⎮ string
6349
* [.getFullName()](#markdown-header-ssotokendatagetfullname-nullstring) ⇒ null ⎮ string
6450
* [.getFirstName()](#markdown-header-ssotokendatagetfirstname-nullstring) ⇒ null ⎮ string
6551
* [.getLastName()](#markdown-header-ssotokendatagetlastname-nullstring) ⇒ null ⎮ string
@@ -164,6 +150,14 @@ Get the id of the user in an external system.
164150
Example use case would be to map user from an external store
165151
to the entry defined in the token.
166152

153+
**Kind**: instance method of [SSOTokenData](#markdown-header-new-ssotokendatatokenvals)
154+
### ssoTokenData.getUserUsername() ⇒ null ⎮ string
155+
Get the username of the user accessing.
156+
157+
**Kind**: instance method of [SSOTokenData](#markdown-header-new-ssotokendatatokenvals)
158+
### ssoTokenData.getUserPrimaryEmailAddress() ⇒ null ⎮ string
159+
Get the primary email address of the user accessing.
160+
167161
**Kind**: instance method of [SSOTokenData](#markdown-header-new-ssotokendatatokenvals)
168162
### ssoTokenData.getFullName() ⇒ null ⎮ string
169163
Get either the combined name of the user or the name of the token.

src/lib/SSOToken.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class SSOToken {
8585
CLAIM_INSTANCE_NAME: decoded.instance_name || null,
8686
CLAIM_USER_ID: decoded.sub || null,
8787
CLAIM_USER_EXTERNAL_ID: decoded.external_id || null,
88+
CLAIM_USER_USERNAME: decoded.username || null,
89+
CLAIM_USER_PRIMARY_EMAIL_ADDRESS: decoded.primary_email_address || null,
8890
CLAIM_USER_FULL_NAME: decoded.name || null,
8991
CLAIM_USER_FIRST_NAME: decoded.given_name || null,
9092
CLAIM_USER_LAST_NAME: decoded.family_name || null,

src/lib/SSOTokenData.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class SSOTokenData {
2121
this.instance_name = tokenVals.CLAIM_INSTANCE_NAME;
2222
this.sub = tokenVals.CLAIM_USER_ID;
2323
this.external_id = tokenVals.CLAIM_USER_EXTERNAL_ID;
24+
this.username = tokenVals.CLAIM_USER_USERNAME;
25+
this.primary_email_address = tokenVals.CLAIM_USER_PRIMARY_EMAIL_ADDRESS;
2426
this.name = tokenVals.CLAIM_USER_FULL_NAME;
2527
this.given_name = tokenVals.CLAIM_USER_FIRST_NAME;
2628
this.family_name = tokenVals.CLAIM_USER_LAST_NAME;
@@ -113,6 +115,8 @@ class SSOTokenData {
113115
instance_name: this.instance_name,
114116
sub: this.sub,
115117
external_id: this.external_id,
118+
username: this.username,
119+
primary_email_address: this.primary_email_address,
116120
name: this.name,
117121
given_name: this.given_name,
118122
family_name: this.family_name,
@@ -139,6 +143,8 @@ class SSOTokenData {
139143
CLAIM_INSTANCE_NAME: this.instance_name,
140144
CLAIM_USER_ID: this.sub,
141145
CLAIM_USER_EXTERNAL_ID: this.external_id,
146+
CLAIM_USER_USERNAME: this.username,
147+
CLAIM_USER_PRIMARY_EMAIL_ADDRESS: this.primary_email_address,
142148
CLAIM_USER_FULL_NAME: this.name,
143149
CLAIM_USER_FIRST_NAME: this.given_name,
144150
CLAIM_USER_LAST_NAME: this.family_name,
@@ -247,6 +253,24 @@ class SSOTokenData {
247253
return this._getClaim('CLAIM_USER_EXTERNAL_ID');
248254
}
249255

256+
/**
257+
* Get the username of the user accessing.
258+
*
259+
* @return {null|string}
260+
*/
261+
getUserUsername() {
262+
return this._getClaim('CLAIM_USER_USERNAME');
263+
}
264+
265+
/**
266+
* Get the primary email address of the user accessing.
267+
*
268+
* @return {null|string}
269+
*/
270+
getUserPrimaryEmailAddress() {
271+
return this._getClaim('CLAIM_USER_PRIMARY_EMAIL_ADDRESS');
272+
}
273+
250274
/**
251275
* Get either the combined name of the user or the name of the token.
252276
*

src/tests/SSOToken.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const tokenDataVals = {
2626
CLAIM_INSTANCE_NAME: 'Our locations',
2727
CLAIM_USER_ID: '541954c3e4b08bbdce1a340a',
2828
CLAIM_USER_EXTERNAL_ID: 'jdoe',
29+
CLAIM_USER_USERNAME: 'john.doe',
30+
CLAIM_USER_PRIMARY_EMAIL_ADDRESS: 'jdoe@email.com',
2931
CLAIM_USER_FULL_NAME: 'John Doe',
3032
CLAIM_USER_FIRST_NAME: 'John',
3133
CLAIM_USER_LAST_NAME: 'Doe',
@@ -150,6 +152,8 @@ describe('Testing SSOToken Class', () => {
150152
family_name: 'Doe',
151153
given_name: 'John',
152154
external_id: 'jdoe',
155+
username: 'john.doe',
156+
primary_email_address: 'jdoe@email.com',
153157
iat: curTime,
154158
instance_id: '55c79b6ee4b06c6fb19bd1e2',
155159
instance_name: 'Our locations',

src/tests/SSOTokenData.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const tokenDataVals = {
1818
CLAIM_INSTANCE_NAME: 'Our locations',
1919
CLAIM_USER_ID: '541954c3e4b08bbdce1a340a',
2020
CLAIM_USER_EXTERNAL_ID: 'jdoe',
21+
CLAIM_USER_USERNAME: 'john.doe',
22+
CLAIM_USER_PRIMARY_EMAIL_ADDRESS: 'jdoe@email.com',
2123
CLAIM_USER_FULL_NAME: 'John Doe',
2224
CLAIM_USER_FIRST_NAME: 'John',
2325
CLAIM_USER_LAST_NAME: 'Doe',

src/utils/tokenDataConsts.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const constants = {
88
CLAIM_INSTANCE_NAME: 'instance_name',
99
CLAIM_USER_ID: 'sub',
1010
CLAIM_USER_EXTERNAL_ID: 'external_id',
11+
CLAIM_USER_USERNAME: 'username',
12+
CLAIM_USER_PRIMARY_EMAIL_ADDRESS: 'primary_email_address',
1113
CLAIM_USER_FULL_NAME: 'name',
1214
CLAIM_USER_FIRST_NAME: 'given_name',
1315
CLAIM_USER_LAST_NAME: 'family_name',

0 commit comments

Comments
 (0)