summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2014-09-18 08:55:41 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2014-09-18 09:57:14 (GMT)
commite2fc0a278caf78802a8dce926b18516a80ea382e (patch)
treef20072749b13499843dd3b7e5596c66971b625f7
downloadwcs-api-master.zip
wcs-api-master.tar.gz
wcs-api-master.tar.bz2
Add PHP implmentation of WCS signature algorithmHEADmaster
-rw-r--r--php/signature.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/php/signature.php b/php/signature.php
new file mode 100644
index 0000000..aee626a
--- /dev/null
+++ b/php/signature.php
@@ -0,0 +1,34 @@
+<?php
+ function wcs_unparse_url($parsed_url) {
+ $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
+ $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
+ $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
+ $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
+ $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
+ $pass = ($user || $pass) ? "$pass@" : '';
+ $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
+ $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
+ $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
+ return "$scheme$user$pass$host$port$path$query$fragment";
+ }
+ function wcs_sign($query, $algo, $key) {
+ return $query . '&signature=' . urlencode(base64_encode(hash_hmac($algo, $query, $key, True)));
+ }
+ function wcs_signature($url, $algo, $key) {
+ $parsed_url = parse_url($url);
+ $signed_data = $parsed_url['query'];
+ if ($signed_data != "") {
+ $signed_data .= "&";
+ }
+ $signed_data .= 'hash=' . urlencode($algo);
+ $signed_data .= '&timestamp=' . urlencode(str_replace('+0000', 'Z', gmdate(DATE_ISO8601)));
+ echo str_replace('+0000', 'Z', gmdate(DATE_ISO8601)) . "\n";
+ $signed_data .= '&nonce=' . rand();
+ echo $signed_data . "\n";
+ $parsed_url['query'] = wcs_sign($signed_data, $algo, $key);
+ return wcs_unparse_url($parsed_url);
+ }
+
+ # $url = 'https://eservices.montpellier-agglo.com/user?format=json&NameID=_1234&orig=compte-citoyen.montpellier-agglo.com';
+ # echo $url . "\n";
+ # echo wcs_signature($url, 'sha256', 'coin') . "\n";