diff --git a/packages/auth-client/src/index.test.ts b/packages/auth-client/src/index.test.ts index 0eacc56d4..668bc0f05 100644 --- a/packages/auth-client/src/index.test.ts +++ b/packages/auth-client/src/index.test.ts @@ -217,17 +217,32 @@ describe('Auth Client login', () => { const client = await AuthClient.create(); // Try without #authorize hash. await client.login({ identityProvider: 'http://localhost' }); - expect(global.open).toBeCalledWith('http://localhost/#authorize', 'idpWindow'); + expect(global.open).toBeCalledWith('http://localhost/#authorize', 'idpWindow', undefined); // Try with #authorize hash. global.open = jest.fn(); await client.login({ identityProvider: 'http://localhost#authorize' }); - expect(global.open).toBeCalledWith('http://localhost/#authorize', 'idpWindow'); + expect(global.open).toBeCalledWith('http://localhost/#authorize', 'idpWindow', undefined); // Default url global.open = jest.fn(); await client.login(); - expect(global.open).toBeCalledWith('https://identity.ic0.app/#authorize', 'idpWindow'); + expect(global.open).toBeCalledWith( + 'https://identity.ic0.app/#authorize', + 'idpWindow', + undefined, + ); + + // Default custom window.open feature + global.open = jest.fn(); + await client.login({ + windowOpenerFeatures: 'toolbar=0,location=0,menubar=0', + }); + expect(global.open).toBeCalledWith( + 'https://identity.ic0.app/#authorize', + 'idpWindow', + 'toolbar=0,location=0,menubar=0', + ); }); it('should ignore authorize-ready events with bad origin', async () => { diff --git a/packages/auth-client/src/index.ts b/packages/auth-client/src/index.ts index c9c794032..b6ca3b4cc 100644 --- a/packages/auth-client/src/index.ts +++ b/packages/auth-client/src/index.ts @@ -1,6 +1,5 @@ /** @module AuthClient */ import { - Actor, AnonymousIdentity, DerEncodedPublicKey, Identity, @@ -64,6 +63,11 @@ export interface AuthClientLoginOptions { * @default BigInt(8) hours * BigInt(3_600_000_000_000) nanoseconds */ maxTimeToLive?: bigint; + /** + * Auth Window feature config string + * @example "toolbar=0,location=0,menubar=0,width=500,height=500,left=100,top=100" + */ + windowOpenerFeatures?: string; /** * Callback once login has completed */ @@ -327,13 +331,15 @@ export class AuthClient { * @param {AuthClientLoginOptions} options * @param options.identityProvider Identity provider * @param options.maxTimeToLive Expiration of the authentication in nanoseconds + * @param options.windowOpenerFeatures Configures the opened authentication window * @param options.onSuccess Callback once login has completed * @param options.onError Callback in case authentication fails * @example * const authClient = await AuthClient.create(); * authClient.login({ * identityProvider: 'http://.localhost:8000', - * maxTimeToLive: BigInt (7) * BigInt(24) * BigInt(3_600_000_000_000) // 1 week + * maxTimeToLive: BigInt (7) * BigInt(24) * BigInt(3_600_000_000_000), // 1 week + * windowOpenerFeatures: "toolbar=0,location=0,menubar=0,width=500,height=500,left=100,top=100", * onSuccess: () => { * console.log('Login Successful!'); * }, @@ -353,6 +359,11 @@ export class AuthClient { * @default BigInt(8) hours * BigInt(3_600_000_000_000) nanoseconds */ maxTimeToLive?: bigint; + /** + * Auth Window feature config string + * @example "toolbar=0,location=0,menubar=0,width=500,height=500,left=100,top=100" + */ + windowOpenerFeatures?: string; /** * Callback once login has completed */ @@ -393,7 +404,9 @@ export class AuthClient { window.addEventListener('message', this._eventHandler); // Open a new window with the IDP provider. - this._idpWindow = window.open(identityProviderUrl.toString(), 'idpWindow') ?? undefined; + this._idpWindow = + window.open(identityProviderUrl.toString(), 'idpWindow', options?.windowOpenerFeatures) ?? + undefined; // Check if the _idpWindow is closed by user. const checkInterruption = (): void => {