src/main/js/oidc-connector.js
/**
     * Start a login session.
     * @param {OIDCConnect.doConnectParameters}
     * @returns {Window|Element} returns the new window object if method is window, or iframe element if inline.
     * @memberOf OIDCConnect
     */
Start a login session.
@param {OIDCConnect.doConnectParameters}
@returns {Window|Element} returns the new window object if method is window, or iframe element if inline.
Start a login session . @param { OIDCConnect . doConnectParameters } @returns { Window|Element } returns the new window object if method is window or iframe element if inline .
function doConnect(  { callback=null, config={}, inlineOnLoadCallback=null, inlineElementID=null } = {} ) {
        const clientConfig = getUpdatedClientConfig( config );
        const authorizeUrl = createAuthorizeClientUrl( clientConfig );
        const method = ( config && config.method ) ? config.method : CONFIG.method;
        switch ( method ) {
            case 'window': {
                const windowWidth = 500;
                const windowHeight = 500;
                const windowLeft = window.top.outerWidth / 2 + window.top.screenX - ( windowWidth / 2 );
                const windowTop = window.top.outerHeight / 2 + window.top.screenY - ( windowHeight / 2 );
                if ( loginWindow ) {
                    loginWindow.close();
                }
                loginWindow = window.open( authorizeUrl, CONNECTOR_CONSTANTS.WINDOW_NAME,
                    [
                        'toolbar=no',
                        'location=no',
                        'status=no',
                        'menubar=no',
                        'scrollbars=yes',
                        'resizable=yes',
                        `width=${windowWidth}px`,
                        `height=${windowHeight}px`,
                        `left=${windowLeft}`,
                        `top=${windowTop}`
                    ].join( ',' ) );
                doHandlePostMessage( {
                    element: context,
                    loginWindow: loginWindow,
                    once: true,
                    callback: callback
                } );
                if ( loginWindow ) {
                    loginWindow.focus();
                }
                return loginWindow;
            }
            case 'redirect': {
                window.location.assign( authorizeUrl );
                return null;
            }
            case 'inline': {
                let iframeElement = document.createElement( 'iframe' );
                iframeElement.setAttribute( 'src', authorizeUrl );
                iframeElement.setAttribute( 'frameborder', '0' );
                iframeElement.setAttribute( 'width', '100%' );
                iframeElement.setAttribute( 'height', '100%' );
                iframeElement.onload = () => {
                    if ( inlineOnLoadCallback ) {
                        inlineOnLoadCallback();
                    }
                };
                const inlineElement = document.getElementById( inlineElementID );
                if ( !inlineElement ) {
                    throw Error( `[${TAG}] doConnect - inlineElement ${inlineElementID} not found.` );
                }
                inlineElement.appendChild( iframeElement );
                doHandlePostMessage( {
                    element: context,
                    loginWindow: null,
                    callback: callback,
                    once: true,
                    inlineElement: inlineElement
                } );
                return iframeElement;
            }
        }
    }
function doConnect ( { callback = null , config = { } , inlineOnLoadCallback = null , inlineElementID = null } = { } ) { const clientConfig = getUpdatedClientConfig ( config ) ; const authorizeUrl = createAuthorizeClientUrl ( clientConfig ) ; const method = ( config && config . method ) ? config . method : CONFIG . method ; switch ( method ) { case 'window' : { const windowWidth = 500 ; const windowHeight = 500 ; const windowLeft = window . top . outerWidth / 2 + window . top . screenX - ( windowWidth / 2 ) ; const windowTop = window . top . outerHeight / 2 + window . top . screenY - ( windowHeight / 2 ) ; if ( loginWindow ) { loginWindow . close ( ) ; } loginWindow = window . open ( authorizeUrl , CONNECTOR_CONSTANTS . WINDOW_NAME , [ 'toolbar=no' , 'location=no' , 'status=no' , 'menubar=no' , 'scrollbars=yes' , 'resizable=yes' , ` ${ windowWidth } ` , ` ${ windowHeight } ` , ` ${ windowLeft } ` , ` ${ windowTop } ` ] . join ( ',' ) ) ; doHandlePostMessage ( { element : context , loginWindow : loginWindow , once : true , callback : callback } ) ; if ( loginWindow ) { loginWindow . focus ( ) ; } return loginWindow ; } case 'redirect' : { window . location . assign ( authorizeUrl ) ; return null ; } case 'inline' : { let iframeElement = document . createElement ( 'iframe' ) ; iframeElement . setAttribute ( 'src' , authorizeUrl ) ; iframeElement . setAttribute ( 'frameborder' , '0' ) ; iframeElement . setAttribute ( 'width' , '100%' ) ; iframeElement . setAttribute ( 'height' , '100%' ) ; iframeElement . onload = ( ) => { if ( inlineOnLoadCallback ) { inlineOnLoadCallback ( ) ; } } ; const inlineElement = document . getElementById ( inlineElementID ) ; if ( ! inlineElement ) { throw Error ( ` ${ TAG } ${ inlineElementID } ` ) ; } inlineElement . appendChild ( iframeElement ) ; doHandlePostMessage ( { element : context , loginWindow : null , callback : callback , once : true , inlineElement : inlineElement } ) ; return iframeElement ; } } }
Start a login session.
Start a login session .
// We need to close the window before reopening to trigger focus in a cross-device compatible way