离子NTLM身份验证-IIS [英] Ionic NTLM Authentication - IIS

查看:71
本文介绍了离子NTLM身份验证-IIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am building an iOS mobile application using the Ionic framework. The app will be accessing APIs that will be served by an ASP.NET 5 (MVC 6) application hosted on IIS using Integrated Windows Authentication. The server already has a web interface to it that uses an AngularJS client. I have been trying to get a $http call to the server from within an Ionic/Angularjs controller and have had no luck getting through the IIS Integrated windows authentication (I have tried running on the device/simulator as well as ionic serve). I always get a 401 Unauthorized error. I have tried setting withCredentials to true and passing in a username/password in the request with no luck. When I try to access the API URL from safari on an iPhone (a non-windows environment), I do get the Browser Authentication popup which successfully logs me in on entering my intranet windows username password.

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

I initially had some CORS issues that I have sorted through by adding the CORS service on the server side and also allowing all origins. I also have the proxy setup to avoid CORS issue when testing using ionic serve. Has anyone done something like this before? This is my controller code:

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服务以允许凭据一样.在ConfigureServices函数的Startup.cs文件中,我必须输入以下内容.希望这对以后的人有所帮助.

After several hours of troubleshooting, it was as simple as setting up ASP.NET 5 CORS service to allow credentials. In my Startup.cs file in the ConfigureServices function I had to put in the following. Hope this helps someone else in the future.

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

这篇关于离子NTLM身份验证-IIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆