Learn how to generate X-WSSE Token and how to authorize requests using X-WSSE header authentication.
If you’re not familiar with X-WSSE Token Authentication and why you should use it, go ahead and read this article that contains the basics of this type of authentication.
In this article I’ll describe how to generate a X-WSSE Token using PHP.
function getWsseHeader($username, $secret) {
$nonce = md5(rand());
$created = date('c');
$digest = base64_encode(hash('sha256', $nonce . $created . $secret, false));
$wsseHeader = sprintf(
'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',
$username,
$digest,
$nonce,
$created
);
return $wsseHeader;
}
$xwsse = getWsseHeader("CLIENT_ID", "CLIENT_SECRET");
echo $xwsse;
That’s it. Check my other X-WSSE Articles and learn how to generate the token using other programming languages.