<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <script src="/bundles/scripts?v=uVyZnuKmZPi_LopV_wS-es88QRp5VE615fnFosg_QU41"></script>

</head>
<body>
  <script>
    (function () {
      function post(url, header, okCB, unuthCB) {
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
          if (xhr.readyState == 4 && xhr.status == 401) {
            if (unuthCB) { unuthCB(); }
          } else if (xhr.readyState == 4 && xhr.status == 200) {
            okCB(xhr.responseText);
          }
        };
        xhr.open('POST', url, true);
        if (header) {
          xhr.setRequestHeader(header.name, header.value);
        }
        xhr.setRequestHeader('Accept', 'application/json');
        xhr.withCredentials = true;
        xhr.send(null);
      }

      function getAppCookie(accessToken) {
        post('/appcookie',
            {
              name: 'Authorization',
              value: "Bearer " + accessToken
            },
            function (text) {
              location.href = location.href;
            });
      }

      window.BBAuthClient.BBAuth.getToken()
        .then(function (token) {
          getAppCookie(token);
        });
    })()
  </script>
</body>
</html>