离子 NTLM 身份验证 - IIS.



我正在使用Ionic框架构建一个iOS移动应用程序。该应用将访问将由使用集成 Windows 身份验证托管在 IIS 上的 ASP.NET 5 (MVC 6) 应用程序提供服务的 API。服务器已经有一个使用AngularJS客户端的Web界面。我一直在尝试从Ionic/Angularjs控制器中对服务器进行$http调用,但没有运气通过IIS集成窗口身份验证(我尝试在设备/模拟器上运行以及离子服务)。我总是收到 401 未经授权的错误。我尝试将凭据设置为 true 并在请求中传递用户名/密码,但没有运气。当我尝试从iPhone(非Windows环境)上的safari访问API URL时,我确实会收到浏览器身份验证弹出窗口,该弹出窗口在输入我的内部网Windows用户名密码时成功登录。

我最初遇到了一些 CORS 问题,我已经通过在服务器端添加 CORS 服务并允许所有源来解决。我也有代理设置,以避免在使用离子服务进行测试时出现 CORS 问题。以前有人做过这样的事情吗?这是我的控制器代码:

angular.module('starter.controllers', [])
.controller('AppCtrl', function($scope, $ionicModal, $http) {
$http.defaults.useXDomain = true;
  $http.defaults.withCredentials = true;
  // Form data for the login modal
  $scope.loginData = {};
  // Create the login modal that we will use later
  $ionicModal.fromTemplateUrl('templates/login.html', {
    scope: $scope
  }).then(function(modal) {
    $scope.modal = modal;
  });
  // Triggered in the login modal to close it
  $scope.closeLogin = function() {
    $scope.modal.hide();
  };
  // Open the login modal
  $scope.login = function() {
    $scope.modal.show();
  };
  // Perform the login action when the user submits the login form
  $scope.doLogin = function() {
    console.log('Doing login', $scope.loginData);
    $http.post('http://localhost:8100/api/APIAccount/Login',{withCredentials:true})
    .then(function(response)
 {
   console.log('success');
 }, function(error)  {
   console.log('error');
 });
  };
});

经过几个小时的故障排除,只需设置 5 个 CORS 服务 ASP.NET 允许凭据即可。在我的 Startup.cs 文件中的配置服务函数中,我必须输入以下内容。希望这将在未来对其他人有所帮助。

services.AddCors(options => 
               {
                options.AddPolicy("AllowAllOrigins",
                builder => builder.WithOrigins("http://<domainname>")
                .AllowCredentials());
               });

最新更新