Code Monkey home page Code Monkey logo

ews-javascript-api-auth's People

Contributors

gautamsi avatar tobiasviehweger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ews-javascript-api-auth's Issues

Usage with ews-js-api-browser.

Hi,

I am student trying to create a simple app to communicate with a local exchange server. the server uses ntlm authentication only, and i was wondering if ews-javascript-api-auth and ews-js-api-browser work together in ionic?
some quick experimentation gives me errors ENOENT 'ews-javascript-api-auth\src\ntlmAuthXhrApi.js.map' no such file found.

thanks in advance for any given insight and your time ^^

Usage with typescript?

How were you able to compile this in typescript?
There is no types definition for fetch and there are other issues with bluebird.

React Native support

Is it possible to use ews-javascript-api-auth with react-native?
Now I see errors like "Unable to resolve module https in ntlmAuthXhrApi.js"

Is this a global setting?

I used to instanciate the exchnage service like:

const exchange = new ews.ExchangeService(version);
exchange.Credentials = new ews.ExchangeCredentials(login, pass);
exchange.Url = new ews.Uri(externalServerUrl);

Since the app has to support multiple accounts, calling the code above multiple time with different user and password works fine.

If, however, I use the new ConfigurationApi for NLTM this will change the credentials of all previous instances of ExchangeService, won't it?

ews.ConfigurationApi.ConfigureXHR(new ewsAuth.ntlmAuthXhrApi(login, pass));

How can I use multiple Exchange Services, each with his own credentials (either Basic or NLTM)?

Unexpected Basic authorization instead of NTLM

Hi, I use the following code to send a request to Exchange Server:

var ews = require("ews-javascript-api");
var ewsAuth = require("ews-javascript-api-auth");

var credentials = {
    userName: "myusername",
    password: "mypassword"
}
ews.ConfigurationApi.ConfigureXHR(new ewsAuth.ntlmAuthXhrApi(credentials.userName, credentials.password, true));
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013_SP1);
exch.Credentials = new ews.WebCredentials(credentials.userName, credentials.password);

exch.Url = new ews.Uri("https://outlook.mydomen.ru/Ews/Exchange.asmx");

exch.FindItems(ews.WellKnownFolderName.Inbox, new ews.ItemView(20))
    .then(function (response) {
        console.log('Inbox:', response)
    }, function (errors) {
        console.log('ERROR:', errors)
    });

Then I see in logs that there was Basic in requet Authorization header instead of NTLM:

{
    "url": "https://outlook.mydomen.ru/Ews/Exchange.asmx",
    "headers": {
        "Content-Type": "text/xml; charset=utf-8",
        "Accept": "text/xml",
        "Authorization": "Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk"
    },
    "type": "POST",
    "data": "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:m='http://schemas.microsoft.com/exchange/services/2006/messages' xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'><soap:Header><t:RequestServerVersion Version='Exchange2013_SP1'></t:RequestServerVersion></soap:Header><soap:Body><m:FindItem Traversal='Shallow'><m:ItemShape><t:BaseShape>AllProperties</t:BaseShape></m:ItemShape><m:IndexedPageItemView MaxEntriesReturned='20' Offset='0' BasePoint='Beginning'></m:IndexedPageItemView><m:ParentFolderIds><t:DistinguishedFolderId Id='inbox'></t:DistinguishedFolderId></m:ParentFolderIds></m:FindItem></soap:Body></soap:Envelope>"
}

What should I do to make a NTLM request?

unhandledRejection in ntlmAuthXhrApi

I am writing an application to retrieve some emails from a mailbox.
I use "Folder.FindItems" function to search the email items, then loop the search result and bind the EmailMessage.
But our exchange server is not stable. It may throw "connect ECONNREFUSED " error when I bind over 4000 emails.
I would like to catch the error and retry the bind function.
But "ntlmAuthXhrApi.xhr" did not catch the error.
When the mail server throw any error, the application will stop at here.
Could you please change the code to catch the error?

Error Log:

2017-07-20T10:21:06.405Z - error:  Error: connect ECONNREFUSED XXX.XXX.XXX.XXX:443
    at Object.exports._errnoException (util.js:1034:11)
    at exports._exceptionWithHostPort (util.js:1057:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1096:14)
From previous event:
    at ntlmAuthXhrApi.ntlmPreCall (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js:122:16)
    at ntlmAuthXhrApi.xhr (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js:44:19)
From previous event:
    at ntlmAuthXhrApi.xhr (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js:43:16)
    at GetItemRequest.ServiceRequestBase.ValidateAndEmitRequest (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js:408:36)
    at SimpleServiceRequestBase.InternalExecute (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js:50:19)
From previous event:
    at GetItemRequest.SimpleServiceRequestBase.InternalExecute (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js:47:16)
    at MultiResponseServiceRequest.Execute (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js:45:19)
From previous event:
    at GetItemRequest.MultiResponseServiceRequest.Execute (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js:44:16)
    at ExchangeService.InternalBindToItems (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api/js/Core/ExchangeService.js:656:24)
    at ExchangeService.BindToItem (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api/js/Core/ExchangeService.js:438:21)
    at Function.EmailMessage.Bind (/home/uat/CX/cx_omnichannel_email_extract/node_modules/ews-javascript-api/js/Core/ServiceObjects/Items/EmailMessage.js:277:24)
    at _loadEmailInFolder (/home/uat/CX/cx_omnichannel_email_extract/app/facade/email-extraction-server-facade.js:1261:60)

Example:

ews-javascript-api-auth/src/ntlmAuthXhrApi.js

    ntlmAuthXhrApi.prototype.xhr = function (xhroptions, progressDelegate) {
        var _this = this;
        //setup xhr for github.com/andris9/fetch options
        var options = {
            url: xhroptions.url,
            //payload: xhroptions.data,
            headers: xhroptions.headers,
            method: 'GET',
            agent: new https_1.Agent({ keepAlive: true, rejectUnauthorized: !this.allowUntrustedCertificate }) //keepaliveAgent
        };

        return new Promise(function (resolve, reject) {
            _this.ntlmPreCall(options).then(function (optionsWithNtlmHeader) {
                optionsWithNtlmHeader['payload'] = xhroptions.data;
                optionsWithNtlmHeader['method'] = xhroptions.type;
                fetch_1.fetchUrl(xhroptions.url, optionsWithNtlmHeader, function (error, meta, body) {
                    if (error) {
                        reject(error);
                    }
                    else {
                        var xhrResponse = {
                            response: body.toString(),
                            status: meta.status,
                            redirectCount: meta.redirectCount,
                            headers: meta.responseHeaders,
                            finalUrl: meta.finalUrl,
                            responseType: '',
                            statusText: undefined,
                        };

                        if (xhrResponse.status === 200) {
                            resolve(utils_1.setupXhrResponse(xhrResponse));
                        }
                        else {
                            reject(utils_1.setupXhrResponse(xhrResponse));
                        }
                    }
                });
            });
        });
    };

Change to:


    ntlmAuthXhrApi.prototype.xhr = function (xhroptions, progressDelegate) {
        var _this = this;
        //setup xhr for github.com/andris9/fetch options
        var options = {
            url: xhroptions.url,
            //payload: xhroptions.data,
            headers: xhroptions.headers,
            method: 'GET',
            agent: new https_1.Agent({ keepAlive: true, rejectUnauthorized: !this.allowUntrustedCertificate }) //keepaliveAgent
        };

        return new Promise(function (resolve, reject) {
            _this.ntlmPreCall(options).then(function (optionsWithNtlmHeader) {
                optionsWithNtlmHeader['payload'] = xhroptions.data;
                optionsWithNtlmHeader['method'] = xhroptions.type;
                fetch_1.fetchUrl(xhroptions.url, optionsWithNtlmHeader, function (error, meta, body) {
                    if (error) {
                        reject(error);
                    }
                    else {
                        var xhrResponse = {
                            response: body.toString(),
                            status: meta.status,
                            redirectCount: meta.redirectCount,
                            headers: meta.responseHeaders,
                            finalUrl: meta.finalUrl,
                            responseType: '',
                            statusText: undefined,
                        };

                        if (xhrResponse.status === 200) {
                            resolve(utils_1.setupXhrResponse(xhrResponse));
                        }
                        else {
                            reject(utils_1.setupXhrResponse(xhrResponse));
                        }
                    }
                });
            }).catch(function(err){
                reject(err);
            });
        });
    };

ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js

SimpleServiceRequestBase.prototype.InternalExecute = function () {
        //var writer = new Data.EwsServiceXmlWriter();
        //this.WriteSoapRequest(this.url, writer);
        var _this = this;
        //if (!this.Service && !this.Service.Credentials && (!this.Service.Credentials.UserName || this.service.Credentials.Password))
        //    throw new Error("missing credential");
        //var cred = "Basic " + btoa(this.Service.Credentials.UserName + ":" + this.Service.Credentials.Password);
        //var cc = writer.GetXML();
        //var xhrOptions: IXHROptions = {
        //    type: "POST",
        //    data: cc,
        //    url: "https://pod51045.outlook.com/autodiscover/autodiscover.svc",
        //    headers: { "Content-Type": "text/xml", "Authorization": cred },
        //    //customRequestInitializer: function (x) {
        //    //    var m = x;
        //    //}
        //};

        return new Promise_1.Promise(function (successDelegate, errorDelegate) {
            var request = _this.BuildXHR();
            //this.ReadResponsePrivate(response);
            _this.ValidateAndEmitRequest(request).then(function (xhrResponse) {
                var dom = new ExtensionMethods_1.DOMParser();
                var xml2js = new ExtensionMethods_1.xml2JsObject();
                var req = xml2js.parseXMLNode(dom.parseFromString(request.data, "text/xml").documentElement, true);
                EwsLogging_1.EwsLogging.DebugLog(req, true);

                if (xhrResponse.status == 200) {
                    EwsLogging_1.EwsLogging.DebugLog(xhrResponse, true);
                    var ewsXmlReader = new EwsServiceXmlReader_1.EwsServiceXmlReader(xhrResponse.responseText || xhrResponse.response, _this.Service);
                    //EwsLogging.DebugLog(ewsXmlReader.JsObject, true);
                    var serviceResponse = _this.ReadResponsePrivate(ewsXmlReader.JsObject);
                    if (successDelegate)
                        successDelegate(serviceResponse || xhrResponse.responseText || xhrResponse.response);
                }
                else {
                    if (errorDelegate)
                        errorDelegate(_this.ProcessWebException(serviceResponse || xhrResponse.responseText || xhrResponse.response) || serviceResponse);
                }
            }, function (resperr) {
                EwsLogging_1.EwsLogging.Log("Error in calling service, error code:" + resperr.status + "\r\n" + resperr.getAllResponseHeaders());
                if (errorDelegate)
                    errorDelegate(_this.ProcessWebException(resperr) || resperr);
            });
        });
    };

Change To:


SimpleServiceRequestBase.prototype.InternalExecute = function () {
        //var writer = new Data.EwsServiceXmlWriter();
        //this.WriteSoapRequest(this.url, writer);
        var _this = this;
        //if (!this.Service && !this.Service.Credentials && (!this.Service.Credentials.UserName || this.service.Credentials.Password))
        //    throw new Error("missing credential");
        //var cred = "Basic " + btoa(this.Service.Credentials.UserName + ":" + this.Service.Credentials.Password);
        //var cc = writer.GetXML();
        //var xhrOptions: IXHROptions = {
        //    type: "POST",
        //    data: cc,
        //    url: "https://pod51045.outlook.com/autodiscover/autodiscover.svc",
        //    headers: { "Content-Type": "text/xml", "Authorization": cred },
        //    //customRequestInitializer: function (x) {
        //    //    var m = x;
        //    //}
        //};

        return new Promise_1.Promise(function (successDelegate, errorDelegate) {
            var request = _this.BuildXHR();
            //this.ReadResponsePrivate(response);
            _this.ValidateAndEmitRequest(request).then(function (xhrResponse) {
                var dom = new ExtensionMethods_1.DOMParser();
                var xml2js = new ExtensionMethods_1.xml2JsObject();
                var req = xml2js.parseXMLNode(dom.parseFromString(request.data, "text/xml").documentElement, true);
                EwsLogging_1.EwsLogging.DebugLog(req, true);

                if (xhrResponse.status == 200) {
                    EwsLogging_1.EwsLogging.DebugLog(xhrResponse, true);
                    var ewsXmlReader = new EwsServiceXmlReader_1.EwsServiceXmlReader(xhrResponse.responseText || xhrResponse.response, _this.Service);
                    //EwsLogging.DebugLog(ewsXmlReader.JsObject, true);
                    var serviceResponse = _this.ReadResponsePrivate(ewsXmlReader.JsObject);
                    if (successDelegate)
                        successDelegate(serviceResponse || xhrResponse.responseText || xhrResponse.response);
                }
                else {
                    if (errorDelegate)
                        errorDelegate(_this.ProcessWebException(serviceResponse || xhrResponse.responseText || xhrResponse.response) || serviceResponse);
                }
            }, function (resperr) {
                EwsLogging_1.EwsLogging.Log("Error in calling service, error code:" + resperr.status + "\r\n" + ((resperr.getAllResponseHeaders)?resperr.getAllResponseHeaders():""));
                if (errorDelegate)
                    errorDelegate(_this.ProcessWebException(resperr) || resperr);
            });
        });
    };

How to use this? Missing Credentials?

Can't get it work. I get always the message:

"credentials are required to make a service request",

var ews = require("ews-javascript-api");
var ewsAuth = require("ews-javascript-api-auth");
ews.ConfigurationApi.ConfigureXHR(new ewsAuth.ntlmAuthXhrApi(credentials.user, credentials.password));

var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
exch.Url = new ews.Uri("https://myexchange/ews/exchange.asmx");

exch.GetPasswordExpirationDate("[email protected]").then(function(value){
    console.log(value);
},function(err){
    console.log(err);
});

typings ?

any plans to add typings like in the ews-javascript-api ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.