ews-javascript-api
ews-javascript-api copied to clipboard
401 www-authenticate not found on response of second request
hey man, i'm using this in my react app... let xhr = new XhrApi() .useNtlmAuthentication(process.env.REACT_APP_USER, process.env.REACT_APP_PASS); ConfigurationApi.ConfigureXHR(xhr) EwsLogging.DebugLogEnabled = false; var service = new ExchangeService(ExchangeVersion.Exchange2010); service.Credentials = new ExchangeCredentials(process.env.REACT_APP_USER, process.env.REACT_APP_PASS); service.Url = new Uri(process.env.REACT_APP_HOST); var view = new CalendarView(DateTime.Now.Add(-1, "week"), DateTime.Now); // appointments in last one week. service.FindAppointments(WellKnownFolderName.Calendar, view).then((response) => { let appointments = response.Items; let appointment = appointments[0]; console.log("Subject: " + appointment.Subject); console.log("Start Time: " + appointment.Start); console.log("End Time: " + appointment.End); console.log("Recipients: "); appointment.RequiredAttendees.Items.forEach((a) => { console.log(a.Address); }); console.log("unique id: " + appointment.Id.UniqueId, true, true); }, function (error) { console.log(error.stack) })
when i get the 401 unauthorized the error that gets logged is
Error: www-authenticate not found on response of second request
is there anyway you could help me get past this?
when i try basic auth i get
HTTP/1.1 401 Unauthorized Server: Microsoft-IIS/10.0 request-id: a18cfc51-4345-4a6c-b673-87163adb33df Access-Control-Allow-Origin: * WWW-Authenticate: Negotiate WWW-Authenticate: NTLM X-Powered-By: ASP.NET X-FEServer: EXCHANGE16 Date: Thu, 16 Jul 2020 23:03:44 GMT Content-Length: 0
which version of @ewsjs/xhr?
1.4.2
when i try ...
var ntlmXHR = require("./ntlmXHRApi"); EwsLogging.DebugLogEnabled = true; let ntlmXHRApi = new ntlmXHR.ntlmXHRApi(process.env.REACT_APP_USER, process.env.REACT_APP_PASS); var service = new ExchangeService(ExchangeVersion.Exchange2013); service.XHRApi = ntlmXHRApi; service.Credentials = new ExchangeCredentials(process.env.REACT_APP_USER, process.env.REACT_APP_PASS); service.Url = new Uri(process.env.REACT_APP_HOST); var view = new CalendarView(DateTime.Now.Add(-1, "week"), DateTime.Now); // appointments in last one week. service.FindAppointments(WellKnownFolderName.Calendar, view).then((response) => { let appointments = response.Items; let appointment = appointments[0]; console.log("Subject: " + appointment.Subject); console.log("Start Time: " + appointment.Start); console.log("End Time: " + appointment.End); console.log("Recipients: "); appointment.RequiredAttendees.Items.forEach((a) => { console.log(a.Address); }); console.log("unique id: " + appointment.Id.UniqueId, true, true); }, function (error) { console.log(error.stack) })
I get
TypeError: Cannot read property 'create' of undefined at e.xhr (https://beta.completefinancialaid.org/static/js/main.b43a2cdd.chunk.js:1:1467) at t.e.ValidateAndEmitRequest (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:979786) at https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:114444 at R.n._execute (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2795232) at R._resolveFromExecutor (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2826325) at new R (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2819325) at t.InternalExecute (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:114394) at https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:112018 at R.n._execute (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2795232) at R._resolveFromExecutor (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2826325) From previous event: at R.q [as _captureStackTrace] (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2795810) at R._resolveFromExecutor (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2826268) at new R (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2819325) at t.Execute (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:111987) at t.FindItems (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:3585986) at t.FindAppointments (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:3583728) at t.value (https://beta.completefinancialaid.org/static/js/main.b43a2cdd.chunk.js:1:67945) at os (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2687692) at dc (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2705621) at t.unstable_runWithPriority (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2724989) at qi (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2649116) at fc (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2702090) at $s (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2698221) at Js (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2694783) at kc (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2716292) at https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2717537 at tc (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2698369) at qc (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2717522) at Object.t.render (https://beta.completefinancialaid.org/static/js/2.f70c82a4.chunk.js:2:2720516) at Module.1556 (https://beta.completefinancialaid.org/static/js/main.b43a2cdd.chunk.js:1:177821) at i (https://beta.completefinancialaid.org/events:1:1280) at Object.1009 (https://beta.completefinancialaid.org/static/js/main.b43a2cdd.chunk.js:1:565)
this is different that NTLM issue, are you trying to load this in react app? chances are this is not going to work well.
it's not going well, what would be the best way to use this in react?
would it be better to try this on an express server?
use it as backend api in ExpressJs.
using it in React has caveat. see more https://github.com/gautamsi/ews-javascript-api/issues/288#issuecomment-459663547
if you are working on a Exchange Mailbox app then you can use another lib https://github.com/gautamsi/ews-js-api-browser
i'm just trying to get calendar info from our exchanges server is ews-javascript-api ok for that?
this is the lib you want, but you can not do that in React due to Microsoft limitations. you have to create a backend process which can fetch calendar data for you.
that's what i'm working on now I'm still am getting the error TypeError: Cannot read property 'create' of undefined
I guess you are using older implementation of xrhapi, see this
use following code to create xhrapi instance and assign it to XHRApi and try again. you need to install the lib @ewsjs/xhr
import { XhrApi } from "@ewsjs/xhr";
let xhr = new XhrApi()
.useNtlmAuthentication(credentials.userName, credentials.password);
service.XHRApi = xhr;
I am now just getting Error in calling service, error code:undefined
ping me on gitter.im then you can try give me actual code if possible
Hello @gautamsi . Please help with EWS requests from Chrome. Now I have CORS problem. I need to call EWS service with OAuth using OAuthCredentials(accesstToken). And i faced with CORS problem during GetRoomLists() execution
Access to fetch at 'https://outlook.office365.com/Ews/Exchange.asmx' from origin 'https://localhost:3001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
What possible ways of solving this problem may you know ? Thanks
you can not get away from CORS unless you are server admin or have ability to run nginx as reverse proxy in front