ios - Ionic NTLM 身份验证 - IIS

标签 ios asp.net angularjs iis ionic-framework

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

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

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');
 });

  };
});

最佳答案

经过几个小时的故障排除后,这就像设置 ASP.NET 5 CORS 服务以允许凭据一样简单。在我的 Startup.cs 文件中的 ConfigureServices 函数中,我必须输入以下内容。希望这对将来的其他人有帮助。

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

关于ios - Ionic NTLM 身份验证 - IIS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35639691/

相关文章:

ios - watch 套件 : adding "Notifications Scene" to existing watchkit app ios

ASP.NET Core RC2配置自定义AppSettings

asp.net - 在 MVC3 编辑器模板中获取验证属性

javascript - 将响应另存为文件

javascript - 处理 ng-repeat 中的重复元素

ios - 具有异步网络请求的 ReactiveCocoa 排序

ios - 类别中的 NSManagedObject 子类属性

ios - 快速从 DatePicker 获取日期/时间

c# - 是否有以编程方式远程创建 Exchange 邮箱的权威指南?

javascript - 我如何在angularjs中的ng-repeat上实现滑动过滤器