mrbbot / ntlm

🔐 NTLM authentication for Dart/Flutter.
https://pub.dev/packages/ntlm
The Unlicense
14 stars 15 forks source link

Help needed please: Error: XMLHttpRequest error. #17

Open Work90210 opened 3 years ago

Work90210 commented 3 years ago

Please have a look through the below and let me know if I can do anything different

NTLMClient client = new NTLMClient(
    domain: "",
    workstation: "LAPTOP",
    username: "#",
    password: "#",
  );

  client
      .get(Uri.parse(
          "#"))
      .then((res) {
    print(res.body);
  });

I get the following error:

Error: XMLHttpRequest error. dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current packages/http/src/browser_client.dart 84:22 dart-sdk/lib/async/zone.dart 1612:54 runUnary dart-sdk/lib/async/future_impl.dart 152:18 handleValue dart-sdk/lib/async/future_impl.dart 704:44 handleValueCallback dart-sdk/lib/async/future_impl.dart 733:13 _propagateToListeners dart-sdk/lib/async/future_impl.dart 530:7 [_complete] dart-sdk/lib/async/stream_pipe.dart 61:11 _cancelAndValue dart-sdk/lib/async/stream.dart 1219:7 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14 _checkAndCall dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39 dcall dart-sdk/lib/html/dart2js/html_dart2js.dart 37307:58 at Object.createErrorWithStack (http://localhost:50529/dart_sdk.js:5325:12) at Object._rethrow (http://localhost:50529/dart_sdk.js:39283:16) at async._AsyncCallbackEntry.new.callback (http://localhost:50529/dart_sdk.js:39277:13) at Object._microtaskLoop (http://localhost:50529/dart_sdk.js:39109:13) at _startMicrotaskLoop (http://localhost:50529/dart_sdk.js:39115:13) at http://localhost:50529/dart_sdk.js:34651:9

mrbbot commented 3 years ago

Hello. 👋 Please could you provide me with the following information:

Thanks!

Work90210 commented 3 years ago

Hi @mrbbot I am using v^1.3.0 The server is a IIS10 Below is the error

Access to XMLHttpRequest at '#' from origin 'http://localhost:52399' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. browser_client.dart:87 GET #::ERR_FAILED send @ browser_client.dart:87 (anonymous) @ async_patch.dart:45 runUnary @ zone.dart:1612 handleValue @ future_impl.dart:152 handleValueCallback @ future_impl.dart:704 _propagateToListeners @ future_impl.dart:733 [_completeWithValue] @ future_impl.dart:539 (anonymous) @ future_impl.dart:577 _microtaskLoop @ schedule_microtask.dart:40 _startMicrotaskLoop @ schedule_microtask.dart:49 (anonymous) @ async_patch.dart:166 Promise.then (async) _scheduleImmediateWithPromise @ async_patch.dart:164 _scheduleImmediate @ async_patch.dart:136 _scheduleAsyncCallback @ schedule_microtask.dart:69 _rootScheduleMicrotask @ zone.dart:1421 scheduleMicrotask @ zone.dart:1632 [_asyncCompleteWithValue] @ future_impl.dart:576 [_asyncComplete] @ future_impl.dart:571 complete @ future_impl.dart:46 [_complete] @ ticker.dart:389 ticker$.TickerFuture.complete @ ticker.dart:379 [_animateToInternal] @ animation_controller.dart:607 forward @ animation_controller.dart:462 confirm @ ink_ripple.dart:200 [_handleTap] @ ink_well.dart:985 invokeCallback @ recognizer.dart:182 handleTapUp @ tap.dart:607 [_checkUp] @ tap.dart:296 handlePrimaryPointer @ tap.dart:230 handleEvent @ recognizer.dart:475 [_dispatch] @ pointer_router.dart:93 (anonymous) @ pointer_router.dart:138 forEach @ linked_hash_map.dart:21 [_dispatchEventToRoutes] @ pointer_router.dart:136 route @ pointer_router.dart:122 handleEvent @ binding.dart:381 dispatchEvent @ binding.dart:361 dispatchEvent @ binding.dart:278 [_handlePointerEventImmediately] @ binding.dart:316 handlePointerEvent @ binding.dart:280 [_flushPointerEventQueue] @ binding.dart:238 [_handlePointerDataPacket] @ binding.dart:221 invoke1 @ platform_dispatcher.dart:911 invokeOnPointerDataPacket @ platform_dispatcher.dart:170 [_onPointerData] @ pointer_binding.dart:128 (anonymous) @ pointer_binding.dart:562 (anonymous) @ pointer_binding.dart:505 (anonymous) @ pointer_binding.dart:214 Show 18 more frames errors.dart:187 Uncaught (in promise) Error: XMLHttpRequest error. dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current packages/http/src/browser_client.dart 84:22 dart-sdk/lib/async/zone.dart 1612:54 runUnary dart-sdk/lib/async/future_impl.dart 152:18 handleValue dart-sdk/lib/async/future_impl.dart 704:44 handleValueCallback dart-sdk/lib/async/future_impl.dart 733:13 _propagateToListeners dart-sdk/lib/async/future_impl.dart 530:7 [_complete] dart-sdk/lib/async/stream_pipe.dart 61:11 _cancelAndValue dart-sdk/lib/async/stream.dart 1219:7 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14 _checkAndCall dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39 dcall dart-sdk/lib/html/dart2js/html_dart2js.dart 37307:58

at Object.createErrorWithStack (errors.dart:269)
at Object._rethrow (async_patch.dart:200)
at async._AsyncCallbackEntry.new.callback (zone.dart:1339)
at Object._microtaskLoop (schedule_microtask.dart:40)
at _startMicrotaskLoop (schedule_microtask.dart:49)
at async_patch.dart:166

Thanks in advance

mrbbot commented 3 years ago

Ah, it looks like you need to setup CORS headers as described in the Flutter Web section of the README here: https://github.com/mrbbot/ntlm#flutter-web-support

I'm not very familiar with IIS but you should be able to do this with the CORS Module (https://www.iis.net/downloads/microsoft/iis-cors-module) using the configuration reference here: https://docs.microsoft.com/en-us/iis/extensions/cors-module/cors-module-configuration-reference#cors-configuration

Make sure you set it up to accept your development origin (e.g. http://localhost:52399). Note that you may need to reconfigure your IIS server each time you start the Flutter web app, since the port number will be different each time, or you could try use a wildcard rule.

Work90210 commented 3 years ago

Thank you @mrbbot

Could you please also explain to me why I am getting a 402 error when I enable CORS using the chrome extension? The username and password are correct and I can get the data from PostMan when I use the same username and password.

Have I put the incorrect information in? Could you please explain what information goes into what placeholder section. For example, domain? What goes into the domain? the domain of the IIS server for the request or the domain of the web app?

Thank you in advance for your assistance

mrbbot commented 3 years ago

Can I just check, are you getting at 402 (payment required) error or a 401 (unauthorized) error?

How are you enabling CORS using a Chrome extension, or are you referring to the IIS CORS module?

The domain is the NT domain of the user account you're trying to login as. This is not the URL of your Flutter web app or of your IIS server. You may be able to leave this blank, otherwise it should be the uppercase part of the Windows username before the \.

Work90210 commented 3 years ago

I am using Allow CORS chrome extension. The IIS has been configured correctly to allow CORS to any URL.

Sorry, I am getting a 401 error.

I spoke with some JS developers who told me that I need to use JSONP.

mrbbot commented 3 years ago

Sorry I haven't replied in a while, just finished exams. Have you made any progress?