From b60cb3f1db7844f13e3fb7f510462cbb8dc8a052 Mon Sep 17 00:00:00 2001 From: kexkey Date: Mon, 8 Oct 2018 12:03:32 -0400 Subject: [PATCH] Un-tested client examples --- clients/javascript/cyphernode-client.js | 14 ++++++-------- clients/shell/cyphernode-client.sh | 1 - clients/shell/cyphernode.conf | 1 + 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/clients/javascript/cyphernode-client.js b/clients/javascript/cyphernode-client.js index c93506c..c8a008e 100644 --- a/clients/javascript/cyphernode-client.js +++ b/clients/javascript/cyphernode-client.js @@ -1,16 +1,16 @@ CyphernodeClient = function(is_prod) { this.baseURL = is_prod ? 'https://cyphernode:443' : 'https://cyphernode-dev:443' + this.h64 = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9Cg==' + this.api_key = Meteor.settings.CYPHERNODE.api_key }; CyphernodeClient.prototype._post = function(url, postdata, cb) { let urlr = this.baseURL + url; - let h64 = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9Cg==' let current = Math.round(new Date().getTime/1000) + 10 let p64 = btoa('{"id":"${id}","exp":' + current + '}') - let api_key = Meteor.settings.CYPHERNODE.api_key - let s = CryptoJS.HmacSHA256(p64, api_key).toString() - let token = h64 + '.' + p64 + '.' + s + let s = CryptoJS.HmacSHA256(p64, this.api_key).toString() + let token = this.h64 + '.' + p64 + '.' + s HTTP.post( urlr, @@ -27,12 +27,10 @@ CyphernodeClient.prototype._post = function(url, postdata, cb) { CyphernodeClient.prototype._get = function(url, cb) { let urlr = this.baseURL + url; - let h64 = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9Cg==' let current = Math.round(new Date().getTime/1000) + 10 let p64 = btoa('{"id":"${id}","exp":' + current + '}') - let api_key = Meteor.settings.CYPHERNODE.api_key - let s = CryptoJS.HmacSHA256(p64, api_key).toString() - let token = h64 + '.' + p64 + '.' + s + let s = CryptoJS.HmacSHA256(p64, this.api_key).toString() + let token = this.h64 + '.' + p64 + '.' + s HTTP.get(urlr, {headers: {'Authorization': 'Bearer ' + token}}, function (err, resp) { cb(err, resp.data) diff --git a/clients/shell/cyphernode-client.sh b/clients/shell/cyphernode-client.sh index 9d1312b..e904402 100644 --- a/clients/shell/cyphernode-client.sh +++ b/clients/shell/cyphernode-client.sh @@ -7,7 +7,6 @@ invoke_cyphernode() local action=${1} local post=${2} - local h64=$(echo "{\"alg\":\"HS256\",\"typ\":\"JWT\"}" | base64) local p64=$(echo "{\"id\":\"${id}\",\"exp\":$((`date +"%s"`+10))}" | base64) local s=$(echo "$h64.$p64" | openssl dgst -hmac "$key" -sha256 -r | cut -sd ' ' -f1) local token="$h64.$p64.$s" diff --git a/clients/shell/cyphernode.conf b/clients/shell/cyphernode.conf index d19bf3d..fc3c9ff 100644 --- a/clients/shell/cyphernode.conf +++ b/clients/shell/cyphernode.conf @@ -1,3 +1,4 @@ # Provided by cyphernode, see api_auth_docker/README.md +h64='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9Cg==' id=001 key=2df1eeea370eacdc5cf7e96c2d82140d1568079a5d4d87006ec8718a98883b36