gautamsi / ews-javascript-api

EWS API for TypeScript/JavaScript - ported from OfficeDev/ews-managed-api - node, cordova, meteor, Ionic, Electron, Outlook Add-Ins
MIT License
281 stars 72 forks source link

How to accept self signed certificate with ews-js-api-browser? #297

Closed omkar-ramtekkar closed 5 years ago

omkar-ramtekkar commented 5 years ago

I'm using ews-js-api-browser on iOS UIWebView. Getting self signed certificate issue with the EWS request. Is there a way to make ews-js-api-browser working with self signed certificate?

gautamsi commented 5 years ago

I have not tested this. if you have a sample repo with just this issue, i can try run it on my mac and try fix this. browser version depends on the underlying web connection.

does UIWebView perform a CORS check? if yes then it may not work due to Exchange server limitation.

omkar-ramtekkar commented 5 years ago

I do not see CORS issue, as same works perfectly fine with public exchange server having valid certificate. I would like to understand if there is any way to accept self signed certs with XHR? if not then I believe we wont be able to fix this in ews-js-api-browser.

gautamsi commented 5 years ago

I am not an expert on iOS, it seems it needs to be handled at UIWebView level and not the library level.

have you tried this - https://stackoverflow.com/questions/11573164/uiwebview-to-view-self-signed-websites-no-private-api-not-nsurlconnection-i

omkar-ramtekkar commented 5 years ago

Thanks for help Gautam. The solution in link did not help, however I was able to implement it using URLProtocol.

One last thing where in I'm stuck on is "ews-javascript-api-auth", is this available for browser? I tried using it for NTLM auth and on running "npx webpack" command getting following errors

ERROR in ./node_modules/fetch/lib/fetch.js Module not found: Error: Can't resolve 'dns' in '/Volumes/Data/Codebase/GIT/XMIOS/myproduct/Automation/EWSJSCore/EWSJSLibrary/node_modules/fetch/lib' @ ./node_modules/fetch/lib/fetch.js 8:10-24 @ ./node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js @ ./node_modules/ews-javascript-api-auth/src/index.js @ ./src/ewscore.js

ERROR in ./node_modules/request/lib/har.js Module not found: Error: Can't resolve 'fs' in '/Volumes/Data/Codebase/GIT/XMIOS/myproduct/Automation/EWSJSCore/EWSJSLibrary/node_modules/request/lib' @ ./node_modules/request/lib/har.js 3:9-22 @ ./node_modules/request/request.js @ ./node_modules/request/index.js @ ./node_modules/ntlm-client/lib/ntlmrequest.js @ ./node_modules/ntlm-client/lib/index.js @ ./node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js @ ./node_modules/ews-javascript-api-auth/src/index.js @ ./src/ewscore.js

ERROR in ./node_modules/fetch/lib/fetch.js Module not found: Error: Can't resolve 'net' in '/Volumes/Data/Codebase/GIT/XMIOS/myproduct/Automation/EWSJSCore/EWSJSLibrary/node_modules/fetch/lib' @ ./node_modules/fetch/lib/fetch.js 12:10-24 @ ./node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js @ ./node_modules/ews-javascript-api-auth/src/index.js @ ./src/ewscore.js

ERROR in ./node_modules/forever-agent/index.js Module not found: Error: Can't resolve 'net' in '/Volumes/Data/Codebase/GIT/XMIOS/myproduct/Automation/EWSJSCore/EWSJSLibrary/node_modules/forever-agent' @ ./node_modules/forever-agent/index.js 10:10-24 @ ./node_modules/request/request.js @ ./node_modules/request/index.js @ ./node_modules/ntlm-client/lib/ntlmrequest.js @ ./node_modules/ntlm-client/lib/index.js @ ./node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js @ ./node_modules/ews-javascript-api-auth/src/index.js @ ./src/ewscore.js

ERROR in ./node_modules/tough-cookie/lib/cookie.js Module not found: Error: Can't resolve 'net' in '/Volumes/Data/Codebase/GIT/XMIOS/myproduct/Automation/EWSJSCore/EWSJSLibrary/node_modules/tough-cookie/lib' @ ./node_modules/tough-cookie/lib/cookie.js 35:10-24 @ ./node_modules/request/lib/cookies.js @ ./node_modules/request/index.js @ ./node_modules/ntlm-client/lib/ntlmrequest.js @ ./node_modules/ntlm-client/lib/index.js @ ./node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js @ ./node_modules/ews-javascript-api-auth/src/index.js @ ./src/ewscore.js

ERROR in ./node_modules/tunnel-agent/index.js Module not found: Error: Can't resolve 'net' in '/Volumes/Data/Codebase/GIT/XMIOS/myproduct/Automation/EWSJSCore/EWSJSLibrary/node_modules/tunnel-agent' @ ./node_modules/tunnel-agent/index.js 5:10-24 @ ./node_modules/request/lib/tunnel.js @ ./node_modules/request/request.js @ ./node_modules/request/index.js @ ./node_modules/ntlm-client/lib/ntlmrequest.js @ ./node_modules/ntlm-client/lib/index.js @ ./node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js @ ./node_modules/ews-javascript-api-auth/src/index.js @ ./src/ewscore.js

ERROR in ./node_modules/forever-agent/index.js Module not found: Error: Can't resolve 'tls' in '/Volumes/Data/Codebase/GIT/XMIOS/myproduct/Automation/EWSJSCore/EWSJSLibrary/node_modules/forever-agent' @ ./node_modules/forever-agent/index.js 11:10-24 @ ./node_modules/request/request.js @ ./node_modules/request/index.js @ ./node_modules/ntlm-client/lib/ntlmrequest.js @ ./node_modules/ntlm-client/lib/index.js @ ./node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js @ ./node_modules/ews-javascript-api-auth/src/index.js @ ./src/ewscore.js

ERROR in ./node_modules/tunnel-agent/index.js Module not found: Error: Can't resolve 'tls' in '/Volumes/Data/Codebase/GIT/XMIOS/myproduct/Automation/EWSJSCore/EWSJSLibrary/node_modules/tunnel-agent' @ ./node_modules/tunnel-agent/index.js 6:10-24 @ ./node_modules/request/lib/tunnel.js @ ./node_modules/request/request.js @ ./node_modules/request/index.js @ ./node_modules/ntlm-client/lib/ntlmrequest.js @ ./node_modules/ntlm-client/lib/index.js @ ./node_modules/ews-javascript-api-auth/src/ntlmAuthXhrApi.js @ ./node_modules/ews-javascript-api-auth/src/index.js @ ./src/ewscore.js

gautamsi commented 5 years ago

browser handles things differently, ews-javascript-api-auth works on nodejs due to various dependency not available in browser.

I am curious how you were able to solve the problem with self signed cert, if it involved forking the XHR part and implement using URLProtocol, you may be able to reuse the logic and create NTLM component yourself. see https://github.com/gautamsi/node-ntlm-client

would you mind sharing the solution for others?

omkar-ramtekkar commented 5 years ago

Yes, I'm thinking the same. Right now, if I intercept all requests from UIWebView, I see that request carrying basic authorization header. However by default Basic is disabled for EWS endpoint. I'm planning to use same URLProtocol and provide credentials when auth challenge comes for NTLM. Let me try it out, if it works then will post some sample code.

gautamsi commented 5 years ago

@ewsjs/xhr and ews-javascript-api-auth (depricated) works in a way by providing an interface and dummy, which is replaced by actual implementation for basic or NTLM.

see this for browser XHR implementation - https://github.com/gautamsi/ews-javascript-api/blob/master/src/js/XHRBrowser.ts

gautamsi commented 5 years ago

no activity, closing. re open if needed.