Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var bodyParser = require('body-parser');
- var soap = require('soap');
- var LOGIN_URL = '...';
- var app = express();
- app.use(bodyParser.json());
- app.get('/', function (req, res) {
- res.send('Hello World!');
- });
- app.post('/api/authenticate/', function (req, res) {
- console.log(req, res);
- var auth = "Basic " + new Buffer(req.body.username + ":" + req.body.password).toString("base64");
- console.log(auth);
- soap.createClient(LOGIN_URL, { wsdl_headers: {Authorization: auth} }, function(err, client) {
- console.log(err);
- if (err === null) {
- res.sendStatus(200);
- }
- else {
- res.sendStatus(401);
- }
- });
- });
- app.listen(3000, function () {
- console.log("Listening on port 3000!");
- });
- // inline testing
- // attempt with correct credentials
- var req = {};
- req.body = {};
- req.body.username = "correctUsername";
- req.body.password = "correctPassword";
- var auth = "Basic " + new Buffer(req.body.username + ":" + req.body.password).toString("base64");
- console.log(auth);
- soap.createClient(LOGIN_URL, { wsdl_headers: {Authorization: auth} }, function(err, client) {
- console.log(err);
- if (err === null) {
- console.log("ok1");
- }
- else {
- console.log("not ok1");
- }
- });
- // => "ok1"
- // attempt with incorrect credentials
- req.body.username = "incorrectUsername";
- var auth = "Basic " + new Buffer(req.body.username + ":" + req.body.password).toString("base64");
- console.log(auth);
- soap.createClient(LOGIN_URL, { wsdl_headers: {Authorization: auth} }, function(err, client) {
- console.log(err);
- if (err === null) {
- console.log("ok2");
- }
- else {
- console.log("not ok2");
- }
- });
- // => "not ok2"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement