Sticky FAQs

»

ID #1193

How can I generate HMAC Muse Proxy proxified links in PHP?

The instructions and code provided below are based on the following assumptions:
-  MuseProxyFoundationHMAC  is the Muse Proxy application configured with HMAC authentication;
-  quiet  is the value of the secret;
-  userName  and  timestamp  are the signature parameters;
-  SHA256  is the algorithm;
- the separator between the signature parameters is . .

Add the following code into your PHP page:

<?php
        require_once './MuseProxyHMAC.php';
        $museProxyURL = "http://MUSE_PROXY_HOST:PORT";
        $applicationID = "MuseProxyFoundationHMAC";
        $secret = "quiet";
        $algorithm = "sha256";
        $separator = ".";
        // $timestamp is the current unix timestamp
        $timestamp = time();
        // $userAgent represent the userAgent from the request
        //$userAgent = filter_input(INPUT_SERVER, "HTTP_USER_AGENT");
        // $referer represent the referer from the request
        //$referer = filter_input(INPUT_SERVER, "REQUEST_SCHEME") . "://" . filter_input(INPUT_SERVER, "HTTP_HOST") . filter_input(INPUT_SERVER, "REQUEST_URI");
        // $userAddress represents the remote adress
        //$userAddress = gethostbyname(gethostbyaddr(filter_input(INPUT_SERVER, "REMOTE_ADDR")));
        //The order from this array must be the same with order and parameters name from the hmac configuration file ${APPLICATION_HOME}/profiles/login/ProxyLoginModuleHMAC.xml.
        //$used_params = array("userName" => "MuseProxyFoundation", "ts" => $timestamp, "userAgent" => $userAgent, "referer" => $referer, "userAddress" => $userAddress);
        $used_params = array("userName" => $applicationID, "ts" => $timestamp);

        $museProxy = new MuseProxyHMAC($museProxyURL, $applicationID, $secret, $algorithm, $separator, $used_params);

        echo $museProxy->generatedHmacDigest . "<br/>";
        echo "<a href='" . $museProxy->generatedURL . "' target='_blank'>TEST<a/>";
        ?>

where replace  MUSE_PROXY_HOST:PORT  with your actual Muse Proxy host and port.

The aditional MuseProxyHMAC.php  file can be downloaded from here.

The code will generate the HMAC link on the TEST label.

The commented lines are for the cases when you want to use in the signature the  userAgent/referer/userAddress  values.
Note that they must be specified in the Muse Proxy as well (in the  $MUSE_HOME\proxy\webcontexts\Applications\MuseProxyFoundationHMAC
\profiles\login\ProxyLoginModuleHMAC.xml
  file).

Tags: can, generate, HMAC, how, links, muse, PHP, proxified, proxy

Related entries: -

Last update: 2017-05-23 12:31
Author: Administrator
Revision: 1.7

Print this record Send FAQ to a friend Show this as PDF file
Rate this FAQ

Average rating: 0 (0 Votes)

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry

powered by phpMyFAQ 2.7.2