Last active
February 12, 2016 20:34
-
-
Save bake/453d0b352747199a1c98 to your computer and use it in GitHub Desktop.
Rocket-Beans-TV-API-WSSE-Authentication https://github.com/BakeRolls/rbapi.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var moment = require('moment'); | |
var sha1h = require('sha1-hex'); | |
var rand = function(num) { | |
return Math.random().toString(36).slice(num); | |
}; | |
var base64encode = function(str) { | |
return new Buffer(str).toString('base64') | |
}; | |
var rbtv = function(endpoint, callback) { | |
var user = ''; | |
var salt = ''; | |
var id = '00000000-0000-0000-0000-000000000000'; | |
var created = moment().format("YYYY-MM-DDTHH:mm:ssZZ").trim(); | |
var nonce = id + created + rand(10).trim(); | |
var sha1 = sha1h(nonce + created + salt); | |
http.request({ | |
host: 'api.rocketmgmt.de', | |
path: '/' + endpoint, | |
headers: { | |
'Accept': 'application/json', | |
'Authorization': 'WSSE profile="UsernameToken"', | |
'X-WSSE': 'UsernameToken Username="' + user + '", PasswordDigest="' + base64encode(sha1) + '", Nonce="' + base64encode(nonce) + '", Created="' + created + '"' | |
} | |
}, function(response) { | |
var json = '' | |
response.on('data', function (chunk) { | |
json += chunk; | |
}); | |
response.on('end', function () { | |
callback(json); | |
}); | |
}).end(); | |
}; | |
rbtv('podcast', function(json) { | |
console.log(json); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment