Skip to content

Commit c0ac194

Browse files
authored
feat(passport): ID-3991-login-prompt-anonymousId (#2727)
1 parent 6c0b4d2 commit c0ac194

4 files changed

Lines changed: 38 additions & 9 deletions

File tree

packages/passport/sdk/src/authManager.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,5 +1324,21 @@ describe('AuthManager', () => {
13241324

13251325
expect(mockSigninPopup).not.toHaveBeenCalled();
13261326
});
1327+
1328+
it('should pass anonymousId to displayEmbeddedLoginPrompt', async () => {
1329+
const anonymousId = 'test-anonymous-id-12345';
1330+
const mockEmbeddedLoginPromptResult = {
1331+
directLoginMethod: 'google' as const,
1332+
marketingConsentStatus: MarketingConsentStatus.OptedIn,
1333+
imPassportTraceId: 'test-trace-id',
1334+
};
1335+
mockEmbeddedLoginPrompt.displayEmbeddedLoginPrompt.mockResolvedValue(mockEmbeddedLoginPromptResult);
1336+
mockSigninPopup.mockResolvedValue(mockOidcUser);
1337+
1338+
await authManager.login(anonymousId);
1339+
1340+
expect(mockEmbeddedLoginPrompt.displayEmbeddedLoginPrompt).toHaveBeenCalledWith(anonymousId);
1341+
expect(mockEmbeddedLoginPrompt.displayEmbeddedLoginPrompt).toHaveBeenCalledTimes(1);
1342+
});
13271343
});
13281344
});

packages/passport/sdk/src/authManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export default class AuthManager {
250250
const {
251251
imPassportTraceId: embeddedLoginPromptImPassportTraceId,
252252
...embeddedLoginPromptDirectLoginOptions
253-
} = await this.embeddedLoginPrompt.displayEmbeddedLoginPrompt();
253+
} = await this.embeddedLoginPrompt.displayEmbeddedLoginPrompt(anonymousId);
254254
directLoginOptionsToUse = embeddedLoginPromptDirectLoginOptions;
255255
imPassportTraceId = embeddedLoginPromptImPassportTraceId;
256256
}

packages/passport/sdk/src/confirmation/embeddedLoginPrompt.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ describe('EmbeddedLoginPrompt', () => {
6565
const href = (embeddedLoginPrompt as any).getHref();
6666
expect(href).toBe(`https://auth.immutable.com/im-embedded-login-prompt?client_id=${mockClientId}&rid=undefined`);
6767
});
68+
69+
it('should generate correct href with anonymous ID', () => {
70+
const anonymousId = 'hello-world-123';
71+
const href = (embeddedLoginPrompt as any).getHref(anonymousId);
72+
expect(href).toBe('https://auth.immutable.com/im-embedded-login-prompt?'
73+
+ `client_id=${mockClientId}&rid=undefined&third_party_a_id=${anonymousId}`);
74+
});
6875
});
6976

7077
describe('appendIFrameStylesIfNeeded', () => {

packages/passport/sdk/src/confirmation/embeddedLoginPrompt.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ export default class EmbeddedLoginPrompt {
2020
this.config = config;
2121
}
2222

23-
private getHref = () => (
24-
`${this.config.authenticationDomain}/im-embedded-login-prompt`
23+
private getHref = (anonymousId?: string) => {
24+
let href = `${this.config.authenticationDomain}/im-embedded-login-prompt`
2525
+ `?client_id=${this.config.oidcConfiguration.clientId}`
26-
+ `&rid=${getDetail(Detail.RUNTIME_ID)}`
27-
);
26+
+ `&rid=${getDetail(Detail.RUNTIME_ID)}`;
27+
28+
if (anonymousId) {
29+
href += `&third_party_a_id=${anonymousId}`;
30+
}
31+
32+
return href;
33+
};
2834

2935
private static appendIFrameStylesIfNeeded = () => {
3036
if (document.getElementById(LOGIN_PROMPT_KEYFRAME_STYLES_ID)) {
@@ -71,10 +77,10 @@ export default class EmbeddedLoginPrompt {
7177
document.head.appendChild(style);
7278
};
7379

74-
private getEmbeddedLoginIFrame = () => {
80+
private getEmbeddedLoginIFrame = (anonymousId?: string) => {
7581
const embeddedLoginPrompt = document.createElement('iframe');
7682
embeddedLoginPrompt.id = LOGIN_PROMPT_IFRAME_ID;
77-
embeddedLoginPrompt.src = this.getHref();
83+
embeddedLoginPrompt.src = this.getHref(anonymousId);
7884
embeddedLoginPrompt.style.height = '100vh';
7985
embeddedLoginPrompt.style.width = '100vw';
8086
embeddedLoginPrompt.style.maxHeight = `${LOGIN_PROMPT_WINDOW_HEIGHT}px`;
@@ -90,9 +96,9 @@ export default class EmbeddedLoginPrompt {
9096
return embeddedLoginPrompt;
9197
};
9298

93-
public displayEmbeddedLoginPrompt(): Promise<EmbeddedLoginPromptResult> {
99+
public displayEmbeddedLoginPrompt(anonymousId?: string): Promise<EmbeddedLoginPromptResult> {
94100
return new Promise((resolve, reject) => {
95-
const embeddedLoginPrompt = this.getEmbeddedLoginIFrame();
101+
const embeddedLoginPrompt = this.getEmbeddedLoginIFrame(anonymousId);
96102
const messageHandler = ({ data, origin }: MessageEvent) => {
97103
if (
98104
origin !== this.config.authenticationDomain

0 commit comments

Comments
 (0)