Custom proxy authentication
When using a proxy service, there are times when the proxy will request authentication. OpenFin handles this by presenting the user with a minimalist dialog box to gather the user's credentials.
While the functionality of that dialog cannot be denied, some might want to present a custom dialog box that includes more information, or one that is styled differently, or to not show a dialog box at all.
Customizing proxy authentication behavior
Proxy authentication is initiated by an HTTP 407 error code sent by the proxy server. OpenFin handles the 407 event and brings up the minimalist dialog box.
The way to create your own customized proxy authentication is to handle the HTTP 407 event yourself. That is done by adding an event handler to the window-auth-requested
. When you add your own event handler, the OpenFin runtime won't automatically bring up the default proxy authentication dialog box.
How to create a custom proxy authentication
By using the application on('window-auth-requested', event => {})
function and verifying that the authentication is for a proxy by using if (event.authInfo.isProxy)
, a custom proxy authentication can be created.
The simplest proxy authentication UI is to, essentially, do nothing. Here is how to do it:
// Get the application object.
let app = fin.Application.getCurrentSync();
// Add the proxy authorization event handler.
app.on('window-auth-requested', event => {
// Verify that proxy authentication is requested.
if (event.authInfo.isProxy) {
// Log the event instead of showing an authentication dialog box.
console.log('No authentication dialog.');
}
});
Another option is to customize the OpenFin proxy authentication dialog box:
// Get the application object.
let app = fin.Application.getCurrentSync();
// Add the proxy authorization event handler.
app.on('window-auth-requested', event => {
// Verify that proxy authentication is requested.
if (event.authInfo.isProxy) {
// Collect the details about this proxy authentication event.
const identity = { uuid: event.uuid, name: event.name};
// Create an authentication dialog box which shows
// the details of this proxy authentication event.
createAuthUI(identity, loginPageUrl);
}
});
You can also do anything you would like to do in response to the proxy authentication event.
// Get the application object.
let app = fin.Application.getCurrentSync();
// Add the proxy authorization event handler.
app.on('window-auth-requested', event => {
// Verify that proxy authentication is requested.
if (event.authInfo.isProxy) {
// Replace this code with your own logic.
alert('Do what you want here.');
}
});
See also
Updated 10 months ago