Skip to content

Commit 73013c9

Browse files
authored
Add function to return id_token (for Service Now)
Some IDPs such as OpenAM can be configured to provide both an access_token and an id_token with the callback. This update provides a function that can be called to return the id_token instead of the access_token. The id_token contains a payload with claims related to the authenticated identity. This was required for API integration to Service Now, who told me their service cannot be configured to accept an access_token.
1 parent 7bbfffb commit 73013c9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Service.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,20 @@ Service_.prototype.getAccessToken = function() {
457457
return token.access_token;
458458
};
459459

460+
/**
461+
* Gets an id token for this service. This token can be used in HTTP
462+
* requests to the service's endpoint. This method will throw an error if the
463+
* user's access was not granted or has expired.
464+
* @return {string} An id token.
465+
*/
466+
Service_.prototype.getIdToken = function() {
467+
if (!this.hasAccess()) {
468+
throw new Error('Access not granted or expired.');
469+
}
470+
var token = this.getToken();
471+
return token.id_token;
472+
};
473+
460474
/**
461475
* Resets the service, removing access and requiring the service to be
462476
* re-authorized.

0 commit comments

Comments
 (0)