diff --git a/sdk/src/platform/Platform-spec.ts b/sdk/src/platform/Platform-spec.ts index 1fbee67..386494e 100644 --- a/sdk/src/platform/Platform-spec.ts +++ b/sdk/src/platform/Platform-spec.ts @@ -1200,6 +1200,29 @@ describe('RingCentral.platform.Platform', () => { expect(await platform.discovery().externalDataExpired()).to.equal(false); }); + it('should fetch external discovery successfully when login without initDiscovery data', async () => { + // mock + const initialDiscoveryData = getInitialDiscoveryMockData(); + const externalDiscoveryData = getExternalDiscoveryMockData(); + apiCall('GET', '/.well-known/entry-points/initial?clientId=whatever', initialDiscoveryData); + apiCall('GET', '/.well-known/entry-points/external', externalDiscoveryData); + authentication(); + + const sdk = createSdk({ + enableDiscovery: true, + discoveryServer: 'http://whatever', + discoveryAutoInit: false, + server: '', + }); + const platform = sdk.platform(); + await platform.login({ + code: 'whatever', + }); + const externalData = await platform.discovery().externalData(); + expect(externalData.coreApi.baseUri).to.equal(externalDiscoveryData.coreApi.baseUri); + expect(await platform.discovery().externalDataExpired()).to.equal(false); + }); + it('should fetch external discovery when login without discovery_uri and token_uri', async () => { // mock const initialDiscoveryData = getInitialDiscoveryMockData(); diff --git a/sdk/src/platform/Platform.ts b/sdk/src/platform/Platform.ts index 0d2a1d6..ac4a68b 100644 --- a/sdk/src/platform/Platform.ts +++ b/sdk/src/platform/Platform.ts @@ -549,7 +549,12 @@ export default class Platform extends EventEmitter { if (this._discoveryInitPromise) { await this._discoveryInitPromise; } - const discoveryData = await this._discovery.initialData(); + let discoveryData = await this._discovery.initialData(); + // check if discovery data is initialized successfully + if (!discoveryData) { + // discovery request fail in previous init, try re-fetch discovery + discoveryData = await this._discovery.fetchInitialData(); + } if (!tokenEndpoint) { tokenEndpoint = discoveryData.authApi.defaultTokenUri; }