Tutorial: Proxy.behaviorChange

Proxy.behaviorChange

This tutorial explains how to change proxy default behavior. When a proxy exists, our default behavior shows an auth dialog, and asks users to enter their username and password. If you would like to change the default behavior, you can use the 'window-auth-requested' event to override it.

1. Show customized auth dialog instead of default auth dialog


// Sample code to create a login window. Users can create their own login pages
async function createAuthUI(identity, loginPageUrl, authInfo) {
    const winName = 'my-auth-win-' + Date.now();
    const uriUuid = encodeURIComponent(identity.uuid);
    const uriName = encodeURIComponent(identity.name);

    const url = `http://${authInfo.host}:${authInfo.port}`;
    // login page should handle these query params
	loginPageUrl = `${loginPageUrl}?uuid=${uriUuid}&name=${uriName}&url=${url}`;
	await fin.Window.create({
        url: loginPageUrl,
        uuid: identity.uuid,
        name: winName,
        alwaysOnTop: true,
        autoShow: true,
        defaultCentered: true,
        defaultHeight: 271,
        defaultTop: true,
        defaultWidth: 362,
        frame: false,
        resizable: false		
	});
}

const app = fin.Application.getCurrentSync();
app.on('window-auth-requested', (event) => {
    if (event.authInfo.isProxy) {
        const identity = { uuid: event.uuid, name: event.name};
        createAuthUI(identity, 'userLoginPageUrl', event.authInfo);
    }

});

2. Don't show any auth dialog

const app = fin.Application.getCurrentSync();
app.on('window-auth-requested', event => {
    if (event.authInfo.isProxy) {
        console.log('no auth dialog');
    }
});

3. User defined function. For example, showing a single dialog, alerting a support team and so on.

const app = fin.Application.getCurrentSync();
app.on('window-auth-requested', event => {
    if (event.authInfo.isProxy) {
        // user defined function
        alert('Do whatever you like');
    }
});

Sample event response

{
    "topic":"application",
    "type":"window-auth-requested",
    "uuid":"OpenfinPOC",
    "name":"OpenfinPOC",
    "authInfo":{
        "isProxy":true,
        "scheme":"basic",
        "host":"127.0.0.1",
        "port":8888,
        "realm":"FiddlerProxy (user: 1, pass: 1)"
        }
    }