// jmu, may 2018 var express = require('express'); var app = express(); var https = require('https'); var fs = require('fs'); // this data comes from your IdCS administrator const client_id = "7x7x38873x3348xxxxe242817x0xx005" const secret = "8x1xxxxx-x87x-48x7-xxx6-1x2xxxx80x3x" const idcsHost = 'idcs-xxxxxxxxxx.identity.oraclecloud.com' // var userJSONData = { "mappingAttribute": "userName", "mappingAttributeValue": "alextorrijo", "password": "P3rr301234", "schemas": [ "urn:ietf:params:scim:schemas:oracle:idcs:PasswordAuthenticator" ] }; var userData = JSON.stringify(userJSONData); var resultado = "" const tokenData = "grant_type=client_credentials&scope=urn:opc:idm:__myscopes__"; var token = "" var credentials = Buffer.from(client_id + ":" + secret).toString('base64'); var token_options = { host: idcsHost, port: 443, path: '/oauth2/v1/token', method: 'POST', headers: { "Content-Type": "application/x-www-form-urlencoded", "Authorization": "Basic "+ credentials, "Accept": "application/json, text/plain, */*" } }; app.get('/', function (req, res) { var x = https.request(token_options,function(res){ res.on('data',function(data){ token = JSON.parse(data).access_token; fs.appendFile('logfile.log', token + '\r\n', function(err){;}); var validate_pwd_options = { host: idcsHost, port: 443, path: '/admin/v1/PasswordAuthenticator', method: 'POST', headers: { "Content-Type": "application/scim+json", "Authorization": "Bearer "+ token } }; var y = https.request(validate_pwd_options,function(res){ res.on('data',function(data){ fs.appendFile('logfile.log', data + '\r\n', function(err){;}); resultado = data }); }); y.write(userData); y.end(); }); }); x.write(tokenData); x.end(); res.send(resultado); }); app.listen(3456, function () { console.log('Example app listening on port 3456!'); });