<%@language = "javascript" %>
<% /*
    $Revision$
    $Id$

    File:           fac_goto_logcenter.asp
    Description:    Maakt een JWT code en ga daarmee naar logcenter
    Parameters:
    Context:
    Note:           ?? Is dit effectief eigenlijk niet gewoon een hardcoded fac_sp?
                       Met een IDP initiated SSO?
*/

%>
<!--#include file="../Shared/common.inc"-->
<%
    user.checkAutorisation("WEB_PRSSYS"); // we zijn nog streng
    if (!user.prs_perslid_email())
        shared.internal_error("User needs to have an e-mail address");

    var logcenterurl = S("logcenter_url"); // "http://logc.facws001.sg.nl/branch20182/"; om te testen
    var config = {
                    aud: "logc.facilitor.nl",
                    iss: "FACILITOR",
                    secret: S("logcenter_secret")
                 }

    var oCrypto = new ActiveXObject("SLNKDWF.Crypto");
    var header =
    {
      "typ":"JWT",
      "alg":"HS256"
    };

    var claim =
    {
        iat: Math.round(new Date().getTime() / 1000),
        jti: "#" + user.prs_perslid_email() + "#" + String(new Date().getTime()),
        aud: config.aud,
        iss: config.iss,
        email: user.prs_perslid_email(),
        fac_id: customerId,
        ver: "1.0"
    }

    var sheader   = oCrypto.base64(JSON.stringify(header));
    var sclaim    = oCrypto.base64(JSON.stringify(claim));
    var signature = oCrypto.hex2base64(oCrypto.hex_hmac_sha256(config.secret, sheader + "." + sclaim), false, true);
    var jwt = sheader + "." + sclaim + "." + signature;

    Response.Redirect(logcenterurl + (logcenterurl.indexOf("?")>=0?"&":"?") + "jwt=" + jwt);
%><% ASPPAGE_END(); %> 
