Add new file

This commit is contained in:
Daniel Schubert 2020-12-10 13:33:42 +00:00
commit 7864aa0ed2

42
provision-user.js Normal file
View File

@ -0,0 +1,42 @@
const querystring = require('querystring');
const http = require('http')
//replace "admin:admin" by "admin-user:admin-pass"
const creds = Buffer.from("admin:admin").toString('base64')
// new User data:
const data = querystring.stringify({
userid: 'hulk',
password: '123'
})
// connection params
const options = {
hostname: 'localhost',
port: 8080,
path: '/ocs/v1.php/cloud/users',
method: 'POST',
headers: {
'OCS-APIRequest': 'true',
'Authorization': 'Basic ' + creds,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': data.length
},
}
// request
const req = http.request(options, (res) => {
console.log( data , options )
console.log(`statusCode: ${res.statusCode}`)
res.on('data', (d) => {
process.stdout.write(d)
})
})
req.on('error', (error) => {
console.error(error)
})
req.write(data)
req.end()