diff --git a/appengine/standard/iap/js/poll.js b/appengine/standard/iap/js/poll.js index d14e4a85186..8eddbbcd02e 100644 --- a/appengine/standard/iap/js/poll.js +++ b/appengine/standard/iap/js/poll.js @@ -1,11 +1,11 @@ -// Copyright Google Inc. -// +// Copyright 2017 Google LLC + // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// + // http://www.apache.org/licenses/LICENSE-2.0 -// + // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -54,10 +54,21 @@ function sessionRefreshClicked() { function checkSessionRefresh() { if (iapSessionRefreshWindow != null && !iapSessionRefreshWindow.closed) { - fetch('/favicon.ico').then(function(response) { + // Attempting to start a new session. + // XMLHttpRequests is used by the server to identify AJAX requests + fetch('/favicon.ico', { + method: "GET", + credentials: 'include', + headers: { + 'X-Requested-With': 'XMLHttpRequest' + } + }).then(function(response) { + // Checking if browser has a session for the requested app if (response.status === 401) { + // No new session detected. Try to get a session again window.setTimeout(checkSessionRefresh, 500); } else { + // Session retrieved. iapSessionRefreshWindow.close(); iapSessionRefreshWindow = null; }