summaryrefslogtreecommitdiffstats
path: root/store.html
blob: 795c9997dabb0ee546f803461d4e895c37c4aa07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="fr">
<head>
  <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
  <script type="text/javascript" src="jquery.cookie-1.1.js"></script>
  <script type="text/javascript" src="jquery.qs.js"></script>
  <script type="text/javascript" src="debug.js"></script>
</head>
<body>
  <script>
    var C_ENTITY_ID = "entityID";
    var C_RETURN = "return";
    var C_POLICY = "policy";
    var C_RETURNIDPARAM = "returnIDParam";
    var C_IS_PASSIVE = "isPassive";
    var C_IDP_ENTITY_ID = "IdPentityID";
    var COOKIE_TIMEOUT_DAYS = 730; // 2 years
    var check_requestor_ws = "./check.json";
    var check_requestor_ws_timeout = 3000;
    var ok = true;

    function response(idp_entity_id) {
      debug_alert('query by ' + entity_id);
      if (! return_url) {
        alert("no return url");
        return;
      }
      if (idp_entity_id) {
        $.cookie(C_IDP_ENTITY_ID, idp_entity_id, { expires: COOKIE_TIMEOUT_DAYS });
        if (return_url.indexOf('?') == -1) {
          return_url = return_url + '?';
        } else {
          return_url = return_url + '&';
        }
        return_url = return_url + return_id_param + '=' + escape(idp_entity_id);
      }
      debug_alert('returning to ' + return_url);
      window.location.href = return_url;
    }

    var qs = $.parseQuerystring();
    var entity_id = qs[C_ENTITY_ID];
    var return_url = qs[C_RETURN];
    var return_id_param = C_ENTITY_ID;
    if (C_RETURNIDPARAM in qs) {
      return_id_param = qs[C_RETURNIDPARAM];
    }
    var idp_entity_id = undefined;

    if (check_requestor_ws) {
      ok = false;
      $.ajax({
        url: check_requestor_ws,
        dataType: 'json',
        async: false,
        timeout: check_requestor_ws_timeout,
        data: { 'return': return_url, 'referrer': document.referrer },
        success: function (data) {
          if (data.result == 'ok') {
            ok = true;
          }
        },
        error: function (jqXHR, status) {
          debug_alert("check_requestor_ws failed with status:" + status);
        }
      });
    }
    if (!ok) {
      response();
    } else {
      if (C_IDP_ENTITY_ID in qs) {
        debug_alert('set idp to ' + qs[C_IDP_ENTITY_ID]);
        response(qs[C_IDP_ENTITY_ID]);
      } else {
        response($.cookie(C_IDP_ENTITY_ID));
      }
    }
  </script>
</body>
</html>