UNPKG

@trimble-oss/trimble-id

Version:

Trimble Identity SDK for JavaScript/ TypeScript

202 lines (182 loc) 9.02 kB
// implements IEndpointProvider (function (root, factory) { /* istanbul ignore next */ if (typeof define === 'function' && define.amd) { // AMD define(['./AnalyticsHttpClient'], (AnalyticsHttpClient) => { return factory({ AnalyticsHttpClient: AnalyticsHttpClient, }); }); } else if (typeof exports === 'object') { // CommonJS module.exports = factory({ AnalyticsHttpClient: require('./AnalyticsHttpClient'), }); } else { // Browser globals (Note: root is window) root.FixedEndpointProvider = factory(root); } }(this, function (imports) { /** * @implements {IEndpointProvider} * @description FixedEndpointProvider helps to configure the fixed oauth endpoints like authorization_endpoint, token_endpoint, userinfo_endpoint etc. */ class FixedEndpointProvider { /** * @description Public constructor for FixedEndpointProvider class * @param {string=} authorizationEndpoint The URL for the Trimble Identity authorization endpoint * @param {string=} tokenEndpoint The URL for the Trimble Identity token endpoint * @param {string=} userInfoEndpoint The URL for the Trimble Identity user information endpoint * @param {string=} tokenRevocationEndpoint The URL for the Trimble Identity token revocation endpoint, if not supplied this is computed relative to the token endpoint * @param {string=} jwksEndpoint The URL for the Trimble Identity JSON web keyset endpoint * @remarks All parameters for this constructor are considered obsolete * @remarks Use fluent extensions when constructing a new instance in the future */ constructor(authorizationEndpoint = null, tokenEndpoint = null, userInfoEndpoint = null, /* istanbul ignore next */ tokenRevocationEndpoint = null, /* istanbul ignore next */ jwksEndpoint = null) { this._authorizationEndpoint = authorizationEndpoint; this._tokenEndpoint = tokenEndpoint; this._userInfoEndpoint = userInfoEndpoint; this._tokenRevocationEndpoint = tokenRevocationEndpoint || tokenEndpoint ? (new URL(tokenEndpoint).origin + '/revoke') : null; this._endSessionEndpoint = null; this._jwksEndpoint = jwksEndpoint; //Send analytics this._analyticshttpclient = imports.AnalyticsHttpClient; this._analyticshttpclient.sendInitEvent(this.constructor.name); } /** * @description Add an authorization endpoint * @param {string} authorizationEndpoint The URL for the Trimble Identity authorization endpoint * @returns {IEndpointProvider} A new instance of a FixedEndpointProvider */ WithAuthorizationEndpoint(authorizationEndpoint) { var clone = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this)); clone._authorizationEndpoint = authorizationEndpoint; return clone; } /** * @description Add a token endpoint * @param {string} tokenEndpoint The URL for the Trimble Identity token endpoint * @returns {IEndpointProvider} A new instance of a FixedEndpointProvider */ WithTokenEndpoint(tokenEndpoint) { var clone = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this)); clone._tokenEndpoint = tokenEndpoint; return clone; } /** * @description Add a user info endpoint * @param {string} userInfoEndpoint The URL for the Trimble Identity user information endpoint * @returns {IEndpointProvider} A new instance of a FixedEndpointProvider */ WithUserInfoEndpoint(userInfoEndpoint) { var clone = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this)); clone._userInfoEndpoint = userInfoEndpoint; return clone; } /** * @description Add a token revocation endpoint * @param {string} tokenRevocationEndpoint The URL for the Trimble Identity token revocation endpoint * @returns {IEndpointProvider} A new instance of a FixedEndpointProvider */ WithTokenRevocationEndpoint(tokenRevocationEndpoint) { var clone = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this)); clone._tokenRevocationEndpoint = tokenRevocationEndpoint; return clone; } /** * @description Add an end session endpoint * @param {string} endSessionEndpoint The URL for the Trimble Identity end session endpoint, if not supplied this is computed relative to the token endpoint * @returns {IEndpointProvider} A new instance of a FixedEndpointProvider */ WithEndSessionEndpoint(endSessionEndpoint) { var clone = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this)); clone._endSessionEndpoint = endSessionEndpoint; return clone; } /** * @description Add a JWKS endpoint * @param {string} jwksEndpoint The URL for the Trimble Identity JSON web keyset endpoint * @returns {IEndpointProvider} A new instance of a FixedEndpointProvider */ WithJWKSEndpoint(jwksEndpoint) { var clone = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this)); clone._jwksEndpoint = jwksEndpoint; return clone; } /** * @description Retrieves a URL for the Trimble Identity authorization endpoint * @returns {PromiseLike<string>} A Task that resolves to the value of the URL on completion */ RetrieveAuthorizationEndpoint() { //Send analytics this._analyticshttpclient.sendMethodEvent(this.RetrieveAuthorizationEndpoint.name); var self = this; return new Promise(function (resolve, reject) { resolve(self._authorizationEndpoint); }); } /** * @description Retrieves a URL for the Trimble Identity token endpoint * @returns {PromiseLike<string>} A Task that resolves to the value of the URL on completion */ RetrieveTokenEndpoint() { //Send analytics this._analyticshttpclient.sendMethodEvent(this.RetrieveTokenEndpoint.name); var self = this; return new Promise(function (resolve, reject) { resolve(self._tokenEndpoint); }); } /** * @description Retrieves a URL for the Trimble Identity user information endpoint * @returns {PromiseLike<string>} A Task that resolves to the value of the URL on completion */ RetrieveUserInfoEndpoint() { //Send analytics this._analyticshttpclient.sendMethodEvent(this.RetrieveUserInfoEndpoint.name); var self = this; return new Promise(function (resolve, reject) { resolve(self._userInfoEndpoint); }); } /** * @description Retrieves a URL for the Trimble Identity token revocation endpoint * @returns {PromiseLike<string>} A Task that resolves to the value of the URL on completion */ RetrieveTokenRevocationEndpoint() { //Send analytics this._analyticshttpclient.sendMethodEvent(this.RetrieveTokenRevocationEndpoint.name); var self = this; return new Promise(function (resolve, reject) { resolve(self._tokenRevocationEndpoint); }); } /** * @description Retrieves a URL for the Trimble Identity end session endpoint * @returns {PromiseLike<string>} A Task that resolves to the value of the URL on completion */ RetrieveEndSessionEndpoint() { //Send analytics this._analyticshttpclient.sendMethodEvent(this.RetrieveEndSessionEndpoint.name); var self = this; return new Promise(function (resolve, reject) { resolve(self._endSessionEndpoint); }); } /** * @description Retrieves a URL for the Trimble Identity JSON web keyset endpoint * @returns {PromiseLike<string>} A Task that resolves to the value of the URL on completion */ RetrieveJSONWebKeySetEndpoint() { //Send analytics this._analyticshttpclient.sendMethodEvent(this.RetrieveJSONWebKeySetEndpoint.name); var self = this; return new Promise(function (resolve, reject) { resolve(self._jwksEndpoint); }); } } // Exposed public methods return FixedEndpointProvider; }));