github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/appengine/login/gitkit1/tpl_html_content.go (about)

     1  package gitkit1
     2  
     3  const IDCardHTML = `
     4  
     5    <div id="navbar"></div>
     6    <script type=text/javascript>
     7  
     8      google.identitytoolkit.signInButton(
     9        '#navbar',
    10        {
    11          widgetUrl:   '{{.WidgetURL}}',
    12          signOutUrl:  '{{.SignOutURL}}'
    13        }
    14      );
    15    </script>
    16  `
    17  
    18  const UserInfoHTML = `
    19  {{if not .User}}
    20  
    21  
    22  {{else}}
    23    <p>You are logged in as {{.User.Name}}<br>
    24    ID: {{.User.ID}} <br>
    25    Email: {{.User.Email}}</p>
    26  
    27  {{end}}`
    28  
    29  const widgetHTML = `
    30  
    31  <div id="gitkitWidget"></div>
    32  <script type="text/javascript">
    33  
    34    var brandingURL = "{{ .BrandingURL }}";
    35    var faviconURL  = "{{ .FaviconURL  }}";
    36    var accountChooserConfig = {
    37      title:    'Sign in to {{.SiteName}}',
    38      favicon:  faviconURL,
    39      branding: brandingURL,
    40    };
    41  
    42    // http and relative urls are rejected as 'invalid domain'
    43    // Therefore fallback
    44    if (window.location.hostname == "localhost") {
    45      faviconURL = "";
    46      brandingURL = "";
    47      accountChooserConfig = {};
    48    }
    49  
    50  
    51  
    52  
    53    var signInSuccessUrl  = '{{.SignInSuccessURL}}';
    54    var signOutUrl = '{{.SignOutURL}}';
    55  
    56    // We erred in reversing the forward slash escaping, 
    57    // signInSuccessUrl = signInSuccessUrl.replace('\/', '/');
    58    // it was not necessary
    59  
    60    console.log("signInSuccessUrl: ",signInSuccessUrl, "  ---  ",signOutUrl)
    61  
    62    // siteName required for "manage account"
    63    google.identitytoolkit.start(
    64      '#gitkitWidget',
    65      {
    66        apiKey:           '{{.BrowserAPIKey}}',
    67        signInSuccessUrl: signInSuccessUrl,
    68        signOutUrl:       signOutUrl,
    69        oobActionUrl:     '{{.OOBActionURL}}',
    70        signInOptions:    ['google','facebook'],
    71        siteName:         '{{.SiteName}}',
    72        acUiConfig:        accountChooserConfig,      
    73        queryParameterForSignInSuccessUrl: 'red',
    74        callbacks: {
    75          signInSuccess: function(tokenString, accountInfo, opt_signInSuccessUrl) {
    76            console.log("opt_signInSuccessUrl",opt_signInSuccessUrl);
    77            console.log("accountInfo",accountInfo.email,accountInfo.providerId,accountInfo.displayName);
    78  
    79            // prevents redirect to signInSuccessUrl
    80            // return false; 
    81            return true;
    82          }
    83        },
    84        /*
    85          // https://developers.google.com/identity/toolkit/web/setup-frontend
    86           ajaxSender: function(url, data, completed) { },
    87        */      
    88      },
    89      '{{.POSTBody}}');
    90  
    91  </script>
    92  
    93  `