离子NTLM身份验证

编程入门 行业动态 更新时间:2024-10-23 05:39:52
本文介绍了离子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('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("<domainname>") .AllowCredentials()); });

更多推荐

离子NTLM身份验证

本文发布于:2023-11-26 13:03:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633977.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:离子   身份验证   NTLM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!