Changeset 35331


Ignore:
Timestamp:
2021-09-04T16:25:30+12:00 (3 years ago)
Author:
davidb
Message:

Further refinement of the Google Signin process from the JS/Web Browser side of things

Location:
main/trunk/greenstone3/web/interfaces/default/transform
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/transform/layouts/header.xsl

    r35322 r35331  
    9797    function gslogout(logout_action_url) {
    9898      if (googlesignin_client_id != '') {
    99         googleSignout();
     99        googleLogout();
    100100      }
    101101      window.location = logout_action_url;
     
    187187    function googleSigninInit() {
    188188      gapi.load('auth2', function() {
    189         auth2 = gapi.auth2.init({
     189        var auth2 = gapi.auth2.init({
    190190           client_id: googlesignin_client_id,
    191191           //scope: 'email' // don't need to top up 'profile' with 'email' as not used client side (email is retrieved via GS3 Servlet)
    192         });
     192         })
     193         .then(function() {     
     194           if (typeof optGoogleAuth2InitCallback === "function"){
     195             optGoogleAuth2InitCallback();
     196           }
     197         });
    193198      });
    194199    }
    195200         
    196     function googleSignout() {
     201    function googleLogout() {
    197202      var auth2 = gapi.auth2.getAuthInstance();
    198       auth2.signOut().then(function () {
     203      // Use 'disconnect()' rather than 'signOut()' as this does a deeper logout
     204      // that revokes the user's "Google granted" permission.
     205      // This makes it easier, when using the same browser, to login into Greenstone3
     206      // using a differeng Google sign-in account
     207
     208      auth2.disconnect().then(function () {
    199209        console.log("Google-authenticated User signed out");
    200210      });
  • main/trunk/greenstone3/web/interfaces/default/transform/pages/login.xsl

    r35322 r35331  
    5656            </xsl:text>
    5757      </gsf:style>
    58      
     58
     59        <gsf:variable name="loginErrorMessage"><xsl:value-of select="/page/pageRequest/paramList/param[@name = 'loginMessage']/@value"/></gsf:variable>
     60
     61        <!--
    5962        <xsl:if test="/page/pageRequest/paramList/param[@name = 'loginMessage']/@value">
    60             <div id="gs_error" class="ui-state-error ui-corner-all">
    61                 <span class="ui-icon ui-icon-alert" style="float: left;"><xsl:text> </xsl:text></span><xsl:value-of select="/page/pageRequest/paramList/param[@name = 'loginMessage']/@value"/>
    62             </div>
     63        -->
     64        <xsl:if test="$loginErrorMessage != ''">
     65          <div id="gs_error" class="ui-state-error ui-corner-all">
     66            <span class="ui-icon ui-icon-alert" style="float: left;">
     67              <xsl:text> </xsl:text>
     68            </span>
     69            <xsl:value-of select="$loginErrorMessage"/>
     70          </div>
    6371        <br/>
    6472        </xsl:if>
     
    126134          function onGoogleSigninFailure(error)
    127135          {
    128             console.error(error);
     136             console.error(error);
     137             $("#googlesignin_id_token").val("");
    129138          }
    130139
    131140          function renderButton()
    132141          {
     142            var auth2 = gapi.auth2.getAuthInstance();
     143            if ((gs.variables.loginErrorMessage != "") &amp;&amp; auth2.isSignedIn.get()) {
     144
     145              // IF a Greenstone-login error is being shown on the page (loginErrorMessage)
     146              // AND Google logged-in (isSignedIn)
     147              // => THEN need to trigger a Google-logout, otherwise the
     148              //    the block of code below automatically tiggers a login
     149              //    attempt (using the Google credentials), which (if allowed to
     150              //    happen) then sets up a endless loop of login attempts
     151              googleLogout();
     152            }
     153         
    133154             gapi.signin2.render('mygoogle-signin2', {
    134155               'scope': 'profile email',
     
    142163          }
    143164
    144           window.onload = function() {
     165          function optGoogleAuth2InitCallback() {
    145166            if (gs.variables['googleSigninClientId']) {
     167              // Only trigger the Google Signin button if a client-id has been set in servlet.xml           
    146168              renderButton();
    147169            }
Note: See TracChangeset for help on using the changeset viewer.