Skip to content

Commit b41cf30

Browse files
authored
Supporting isDeeplyNestedAuthSupported flag for Legacy Teams Mobile Scenario (#2803)
* deeplyNesteAuth config for mobile legacy
1 parent 572c1ac commit b41cf30

File tree

4 files changed

+120
-28
lines changed

4 files changed

+120
-28
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Added a new client version `2.1.2` to support isDeeplyNestedAuthSupported for Teams Mobile legacy code",
4+
"packageName": "@microsoft/teams-js",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/teams-js/src/public/nestedAppAuth.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66
import { callFunctionInHostAndHandleResponse, Communication } from '../internal/communication';
77
import { GlobalVars } from '../internal/globalVars';
8-
import { ensureInitialized } from '../internal/internalAPIs';
8+
import { ensureInitialized, isCurrentSDKVersionAtLeast } from '../internal/internalAPIs';
99
import { ResponseHandler, SimpleType } from '../internal/responseHandler';
1010
import { ApiName, ApiVersionNumber, getApiVersionTag } from '../internal/telemetry';
1111
import { errorNotSupportedOnPlatform, HostClientType } from './constants';
12-
import { runtime } from './runtime';
12+
import { runtime, legacyTeamsMobileVersionForDeeplyNestedAuth } from './runtime';
1313
import { ISerializable } from './serializable.interface';
1414

1515
/**
@@ -84,9 +84,21 @@ export function canParentManageNAATrustedOrigins(): boolean {
8484
* @beta
8585
*/
8686
export function isDeeplyNestedAuthSupported(): boolean {
87-
return (ensureInitialized(runtime) && runtime.isDeeplyNestedAuthSupported) ?? false;
87+
return (
88+
(ensureInitialized(runtime) &&
89+
(runtime.isDeeplyNestedAuthSupported || isDeeplyNestedAuthSupportedForLegacyTeamsMobile())) ??
90+
false
91+
);
8892
}
8993

94+
function isDeeplyNestedAuthSupportedForLegacyTeamsMobile(): boolean {
95+
return ensureInitialized(runtime) &&
96+
isHostAndroidOrIOSOrIPadOSOrVisionOS() &&
97+
runtime.isLegacyTeams &&
98+
isCurrentSDKVersionAtLeast(legacyTeamsMobileVersionForDeeplyNestedAuth)
99+
? true
100+
: false;
101+
}
90102
function isNAAChannelRecommendedForLegacyTeamsMobile(): boolean {
91103
return ensureInitialized(runtime) &&
92104
isHostAndroidOrIOSOrIPadOSOrVisionOS() &&

packages/teams-js/src/public/runtime.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,12 @@ export const upgradeChain: IRuntimeUpgrade[] = [
544544
},
545545
];
546546

547+
/**
548+
* This version is for legacy Teams mobile clients that don’t pass a runtime object during initialization.
549+
* It’s the minimum version required to support deeply nested app auth.
550+
*/
551+
export const legacyTeamsMobileVersionForDeeplyNestedAuth = '2.1.2';
552+
547553
/**
548554
* This structure is used for versions of Teams that don't pass a runtime object during initialization.
549555
* Please see the extensive comments in versionAndPlatformAgnosticTeamsRuntimeConfig for more information
@@ -611,6 +617,10 @@ export const mapTeamsVersionToSupportedCapabilities: Record<string, Array<ICapab
611617
hostClientTypes: [HostClientType.android, HostClientType.ios, HostClientType.ipados, HostClientType.visionOS],
612618
},
613619
],
620+
'2.1.2': [
621+
// isDeeplyNestedAuthSupported: true (based on const legacyTeamsMobileVersionForDeeplyNestedAuth)
622+
// for hostClientTypes: [HostClientType.android, HostClientType.ios, HostClientType.ipados, HostClientType.visionOS]
623+
],
614624
};
615625

616626
const generateBackCompatRuntimeConfigLogger = runtimeLogger.extend('generateBackCompatRuntimeConfig');

packages/teams-js/test/public/nestedAppAuth.spec.ts

Lines changed: 88 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import * as communication from '../../src/internal/communication';
22
import { errorLibraryNotInitialized } from '../../src/internal/constants';
33
import { app, FrameContexts, HostClientType, nestedAppAuth } from '../../src/public';
44
import { errorNotSupportedOnPlatform } from '../../src/public/constants';
5-
import { _minRuntimeConfigToUninitialize, Runtime } from '../../src/public/runtime';
5+
import {
6+
_minRuntimeConfigToUninitialize,
7+
Runtime,
8+
legacyTeamsMobileVersionForDeeplyNestedAuth,
9+
} from '../../src/public/runtime';
610
import { Utils } from '../utils';
711

812
/* eslint-disable */
@@ -125,84 +129,143 @@ describe('nestedAppAuth', () => {
125129
});
126130
});
127131
});
128-
describe('canParentManageNAATrustedOrigins', () => {
132+
133+
describe('isDeeplyNestedAuthSupported', () => {
129134
it('should throw if called before initialization', () => {
130135
utils.uninitializeRuntimeConfig();
131-
expect(() => nestedAppAuth.canParentManageNAATrustedOrigins()).toThrowError(
132-
new Error(errorLibraryNotInitialized),
133-
);
136+
expect(() => nestedAppAuth.isDeeplyNestedAuthSupported()).toThrowError(new Error(errorLibraryNotInitialized));
134137
});
135138

136-
it('should return true if canParentManageNAATrustedOrigins set to true in runtime object', async () => {
139+
it('should return true if isDeeplyNestedAuthSupported set to true in runtime object', async () => {
137140
await utils.initializeWithContext(FrameContexts.content);
138141
const runtimeConfig: Runtime = {
139142
apiVersion: 4,
140143
supports: {},
141-
canParentManageNAATrustedOrigins: true,
144+
isDeeplyNestedAuthSupported: true,
142145
};
143146
utils.setRuntimeConfig(runtimeConfig);
144-
expect(nestedAppAuth.canParentManageNAATrustedOrigins()).toBeTruthy();
147+
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeTruthy();
145148
});
146149

147-
it('should return false if canParentManageNAATrustedOrigins set to false in runtime object ', async () => {
150+
it('should return false if isDeeplyNestedAuthSupported set to false in runtime object ', async () => {
148151
await utils.initializeWithContext(FrameContexts.content);
149152
const runtimeConfig: Runtime = {
150153
apiVersion: 4,
151154
supports: {},
152-
canParentManageNAATrustedOrigins: false,
155+
isDeeplyNestedAuthSupported: false,
153156
};
154157
utils.setRuntimeConfig(runtimeConfig);
155-
expect(nestedAppAuth.canParentManageNAATrustedOrigins()).toBeFalsy();
158+
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeFalsy();
156159
});
157160

158-
it('should return false if canParentManageNAATrustedOrigins not present in runtime object ', async () => {
161+
it('should return false if isDeeplyNestedAuthSupported not present in runtime object ', async () => {
159162
await utils.initializeWithContext(FrameContexts.content);
160163
const runtimeConfig: Runtime = {
161164
apiVersion: 4,
162165
supports: {},
163166
};
164167
utils.setRuntimeConfig(runtimeConfig);
165-
expect(nestedAppAuth.canParentManageNAATrustedOrigins()).toBeFalsy();
168+
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeFalsy();
169+
});
170+
171+
describe('should return false when isDeeplyNestedAuthSupported is false across different host clients', () => {
172+
const hostClients = [HostClientType.macos, HostClientType.desktop, HostClientType.web];
173+
174+
hostClients.forEach((hostClient) => {
175+
it(`${hostClient} client`, async () => {
176+
await utils.initializeWithContext(FrameContexts.content, hostClient);
177+
const runtimeConfig: Runtime = {
178+
apiVersion: 4,
179+
supports: {},
180+
isDeeplyNestedAuthSupported: false,
181+
};
182+
utils.setRuntimeConfig(runtimeConfig);
183+
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeFalsy();
184+
});
185+
});
186+
});
187+
188+
it('should return false if isDeeplyNestedAuthSupported is false and isLegacyTeams is false in runtimeConfig', async () => {
189+
await utils.initializeWithContext(FrameContexts.content, HostClientType.android);
190+
const runtimeConfig: Runtime = {
191+
apiVersion: 4,
192+
supports: {},
193+
isDeeplyNestedAuthSupported: false,
194+
isLegacyTeams: false,
195+
};
196+
utils.setRuntimeConfig(runtimeConfig);
197+
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeFalsy();
198+
});
199+
200+
it('should return false if isDeeplyNestedAuthSupported is false and isLegacyTeams is true in runtimeConfig for android client for version < legacyTeamsMobileVersionForDeeplyNestedAuth', async () => {
201+
await utils.initializeWithContext(FrameContexts.content, HostClientType.android);
202+
const runtimeConfig: Runtime = {
203+
apiVersion: 4,
204+
supports: {},
205+
isDeeplyNestedAuthSupported: false,
206+
isLegacyTeams: true,
207+
};
208+
utils.setClientSupportedSDKVersion('2.1.1');
209+
utils.setRuntimeConfig(runtimeConfig);
210+
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeFalsy();
211+
});
212+
213+
describe('should return true if isDeeplyNestedAuthSupported is false and isLegacyTeams is true in runtimeConfig for android clients with version legacyTeamsMobileVersionForDeeplyNestedAuth', () => {
214+
const hostClients = [HostClientType.ipados, HostClientType.ios, HostClientType.android];
215+
hostClients.forEach((hostClient) => {
216+
it(`for ${hostClient} client`, async () => {
217+
await utils.initializeWithContext(FrameContexts.content, hostClient);
218+
utils.setClientSupportedSDKVersion(legacyTeamsMobileVersionForDeeplyNestedAuth);
219+
const runtimeConfig: Runtime = {
220+
apiVersion: 4,
221+
supports: {},
222+
isDeeplyNestedAuthSupported: false,
223+
isLegacyTeams: true,
224+
};
225+
utils.setRuntimeConfig(runtimeConfig);
226+
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeTruthy();
227+
});
228+
});
166229
});
167230
});
168-
describe('nestedAppAuth.isDeeplyNestedAuthSupported', () => {
231+
describe('canParentManageNAATrustedOrigins', () => {
169232
it('should throw if called before initialization', () => {
170233
utils.uninitializeRuntimeConfig();
171-
expect(() => nestedAppAuth.isDeeplyNestedAuthSupported()).toThrowError(new Error(errorLibraryNotInitialized));
234+
expect(() => nestedAppAuth.canParentManageNAATrustedOrigins()).toThrowError(
235+
new Error(errorLibraryNotInitialized),
236+
);
172237
});
173238

174-
it('should return true if isDeeplyNestedAuthSupported set to true in runtime object', async () => {
239+
it('should return true if canParentManageNAATrustedOrigins set to true in runtime object', async () => {
175240
await utils.initializeWithContext(FrameContexts.content);
176241
const runtimeConfig: Runtime = {
177242
apiVersion: 4,
178243
supports: {},
179-
isNAAChannelRecommended: true,
180-
isDeeplyNestedAuthSupported: true,
244+
canParentManageNAATrustedOrigins: true,
181245
};
182246
utils.setRuntimeConfig(runtimeConfig);
183-
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeTruthy();
247+
expect(nestedAppAuth.canParentManageNAATrustedOrigins()).toBeTruthy();
184248
});
185249

186-
it('should return false if isDeeplyNestedAuthSupported set to false in runtime object ', async () => {
250+
it('should return false if canParentManageNAATrustedOrigins set to false in runtime object ', async () => {
187251
await utils.initializeWithContext(FrameContexts.content);
188252
const runtimeConfig: Runtime = {
189253
apiVersion: 4,
190254
supports: {},
191-
isNAAChannelRecommended: false,
255+
canParentManageNAATrustedOrigins: false,
192256
};
193257
utils.setRuntimeConfig(runtimeConfig);
194-
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeFalsy();
258+
expect(nestedAppAuth.canParentManageNAATrustedOrigins()).toBeFalsy();
195259
});
196260

197-
it('should return false if isDeeplyNestedAuthSupported not present in runtime object ', async () => {
261+
it('should return false if canParentManageNAATrustedOrigins not present in runtime object ', async () => {
198262
await utils.initializeWithContext(FrameContexts.content);
199263
const runtimeConfig: Runtime = {
200264
apiVersion: 4,
201265
supports: {},
202-
isNAAChannelRecommended: true,
203266
};
204267
utils.setRuntimeConfig(runtimeConfig);
205-
expect(nestedAppAuth.isDeeplyNestedAuthSupported()).toBeFalsy();
268+
expect(nestedAppAuth.canParentManageNAATrustedOrigins()).toBeFalsy();
206269
});
207270
});
208271
describe('getParentOrigin', () => {

0 commit comments

Comments
 (0)