Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const passportInstanceWithDisabledOverlays = new passport.Passport({
popupOverlayOptions: {
disableGenericPopupOverlay: true,
disableBlockedPopupOverlay: true,
disableHeadlessLoginPromptOverlay: true,
},
});

Expand Down
41 changes: 34 additions & 7 deletions packages/passport/sdk/src/authManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,26 +1045,38 @@ describe('AuthManager', () => {

it('should include direct parameter when directLoginMethod is provided', async () => {
const directLoginMethod = 'apple';
const result = await authManager.getPKCEAuthorizationUrl({ directLoginMethod });
const result = await authManager.getPKCEAuthorizationUrl({
directLoginMethod,
marketingConsentStatus: MarketingConsentStatus.OptedIn,
});
const url = new URL(result);

expect(url.searchParams.get('direct')).toEqual('apple');
expect(url.searchParams.get('marketingConsent')).toEqual(MarketingConsentStatus.OptedIn);
});

it('should include direct parameter for google login method', async () => {
const directLoginMethod = 'google';
const result = await authManager.getPKCEAuthorizationUrl({ directLoginMethod });
const result = await authManager.getPKCEAuthorizationUrl({
directLoginMethod,
marketingConsentStatus: MarketingConsentStatus.OptedIn,
});
const url = new URL(result);

expect(url.searchParams.get('direct')).toEqual('google');
expect(url.searchParams.get('marketingConsent')).toEqual(MarketingConsentStatus.OptedIn);
});

it('should include direct parameter for facebook login method', async () => {
const directLoginMethod = 'facebook';
const result = await authManager.getPKCEAuthorizationUrl({ directLoginMethod });
const result = await authManager.getPKCEAuthorizationUrl({
directLoginMethod,
marketingConsentStatus: MarketingConsentStatus.OptedIn,
});
const url = new URL(result);

expect(url.searchParams.get('direct')).toEqual('facebook');
expect(url.searchParams.get('marketingConsent')).toEqual(MarketingConsentStatus.OptedIn);
});

it('should include audience parameter when specified in config', async () => {
Expand All @@ -1081,7 +1093,10 @@ describe('AuthManager', () => {
const configWithAudience = getConfig({ audience: 'test-audience' });
const am = new AuthManager(configWithAudience, mockEmbeddedLoginPrompt);

const result = await am.getPKCEAuthorizationUrl({ directLoginMethod: 'apple', marketingConsentStatus: MarketingConsentStatus.OptedIn });
const result = await am.getPKCEAuthorizationUrl({
directLoginMethod: 'apple',
marketingConsentStatus: MarketingConsentStatus.OptedIn,
});
const url = new URL(result);

expect(url.searchParams.get('direct')).toEqual('apple');
Expand All @@ -1101,13 +1116,17 @@ describe('AuthManager', () => {
it('should pass directLoginMethod to login popup', async () => {
mockSigninPopup.mockResolvedValue(mockOidcUser);

await authManager.login('anonymous-id', { directLoginMethod: 'apple' });
await authManager.login('anonymous-id', {
directLoginMethod: 'apple',
marketingConsentStatus: MarketingConsentStatus.OptedIn,
});

expect(mockSigninPopup).toHaveBeenCalledWith({
extraQueryParams: {
rid: '',
third_party_a_id: 'anonymous-id',
direct: 'apple',
marketingConsent: MarketingConsentStatus.OptedIn,
},
popupWindowFeatures: {
width: 410,
Expand Down Expand Up @@ -1158,13 +1177,17 @@ describe('AuthManager', () => {
});

it('should pass directLoginMethod to redirect login', async () => {
await authManager.loginWithRedirect('anonymous-id', { directLoginMethod: 'google' });
await authManager.loginWithRedirect('anonymous-id', {
directLoginMethod: 'google',
marketingConsentStatus: MarketingConsentStatus.OptedIn,
});

expect(mockSigninRedirect).toHaveBeenCalledWith({
extraQueryParams: {
rid: '',
third_party_a_id: 'anonymous-id',
direct: 'google',
marketingConsent: MarketingConsentStatus.OptedIn,
},
});
});
Expand Down Expand Up @@ -1223,14 +1246,18 @@ describe('AuthManager', () => {
it('should not call displayEmbeddedLoginPrompt when directLoginOptions are provided', async () => {
mockSigninPopup.mockResolvedValue(mockOidcUser);

await authManager.login('anonymous-id', { directLoginMethod: 'apple' });
await authManager.login('anonymous-id', {
directLoginMethod: 'apple',
marketingConsentStatus: MarketingConsentStatus.OptedIn,
});

expect(mockEmbeddedLoginPrompt.displayEmbeddedLoginPrompt).not.toHaveBeenCalled();
expect(mockSigninPopup).toHaveBeenCalledWith({
extraQueryParams: {
rid: '',
third_party_a_id: 'anonymous-id',
direct: 'apple',
marketingConsent: MarketingConsentStatus.OptedIn,
},
popupWindowFeatures: {
width: 410,
Expand Down
2 changes: 1 addition & 1 deletion packages/passport/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export enum MarketingConsentStatus {
}

export type DirectLoginOptions = {
marketingConsentStatus?: MarketingConsentStatus;
marketingConsentStatus: MarketingConsentStatus;
} & (
| { directLoginMethod: 'email'; email: string }
| { directLoginMethod: Exclude<DirectLoginMethod, 'email'>; email?: never }
Expand Down