js/firebase.js
/**
 * Start the auth flow and authorizes to Firebase.
 * @param{boolean} interactive True if the OAuth flow should request with an interactive mode.
 */
Start the auth flow and authorizes to Firebase.
@param{boolean} interactive True if the OAuth flow should request with an interactive mode.
Start the auth flow and authorizes to Firebase . @param { boolean } interactive True if the OAuth flow should request with an interactive mode .
function startAuth(interactive) {
    chrome.identity.getAuthToken({interactive: !!interactive}, function (token) {
        if (chrome.runtime.lastError && !interactive) {
            console.log('It was not possible to get a token programmatically.');
        } else if (chrome.runtime.lastError) {
            console.error(chrome.runtime.lastError);
        } else if (token) {
            var credential = firebase.auth.GoogleAuthProvider.credential(null, token);
            firebase.auth().signInWithCredential(credential).catch(function (error) {
                if (error.code === 'auth/invalid-credential') {
                    chrome.identity.removeCachedAuthToken({token: token}, function () {
                        startAuth(interactive);
                    });
                }
            });
        } else {
            console.error('The OAuth Token was null');
        }
    });
}
function startAuth ( interactive ) { chrome . identity . getAuthToken ( { interactive : ! ! interactive } , function ( token ) { if ( chrome . runtime . lastError && ! interactive ) { console . log ( 'It was not possible to get a token programmatically.' ) ; } else if ( chrome . runtime . lastError ) { console . error ( chrome . runtime . lastError ) ; } else if ( token ) { var credential = firebase . auth . GoogleAuthProvider . credential ( null , token ) ; firebase . auth ( ) . signInWithCredential ( credential ) . catch ( function ( error ) { if ( error . code === 'auth/invalid-credential' ) { chrome . identity . removeCachedAuthToken ( { token : token } , function ( ) { startAuth ( interactive ) ; } ) ; } } ) ; } else { console . error ( 'The OAuth Token was null' ) ; } } ) ; }
Start the auth flow and authorizes to Firebase.
Start the auth flow and authorizes to Firebase .
// Request an OAuth token from the Chrome Identity API. // Authorize Firebase with the OAuth Access Token. // The OAuth token might have been invalidated. Lets' remove it from cache.