|
1 | | -// Copyright Google Inc. |
2 | | -// |
| 1 | +// Copyright 2017 Google LLC |
| 2 | + |
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | // you may not use this file except in compliance with the License. |
5 | 5 | // You may obtain a copy of the License at |
6 | | -// |
| 6 | + |
7 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | -// |
| 8 | + |
9 | 9 | // Unless required by applicable law or agreed to in writing, software |
10 | 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
@@ -54,10 +54,21 @@ function sessionRefreshClicked() { |
54 | 54 |
|
55 | 55 | function checkSessionRefresh() { |
56 | 56 | if (iapSessionRefreshWindow != null && !iapSessionRefreshWindow.closed) { |
57 | | - fetch('/favicon.ico').then(function(response) { |
| 57 | + // Attempting to start a new session. |
| 58 | + // XMLHttpRequests is used by the server to identify AJAX requests |
| 59 | + fetch('/favicon.ico', { |
| 60 | + method: "GET", |
| 61 | + credentials: 'include', |
| 62 | + headers: { |
| 63 | + 'X-Requested-With': 'XMLHttpRequest' |
| 64 | + } |
| 65 | + }).then(function(response) { |
| 66 | + // Checking if browser has a session for the requested app |
58 | 67 | if (response.status === 401) { |
| 68 | + // No new session detected. Try to get a session again |
59 | 69 | window.setTimeout(checkSessionRefresh, 500); |
60 | 70 | } else { |
| 71 | + // Session retrieved. |
61 | 72 | iapSessionRefreshWindow.close(); |
62 | 73 | iapSessionRefreshWindow = null; |
63 | 74 | } |
|
0 commit comments