.net - Windows 身份验证 - .NET Core Angular 应用程序

标签 .net angular asp.net-core

我正在使用 Visual Studio 2017 构建一个 Intranet 应用程序,并使用模板创建一个带有 Angular 的 .NET Core Web 应用程序。由于是内网应用,我们要实现windows认证。用户已经登录到网络,我们不希望他们在访问应用程序时再次输入凭据。

我如何设置我的 Angular 应用程序,以便它可以识别已经登录到网络的用户并适本地传递它。我们有一个 Web API 身份验证 API,它可以获取此用户 ID 并确定用户所在的 AD 组,以确定对应用程序的授权。

我特别询问的问题是关于 Angular Windows 身份验证的。不是 Web API Windows 身份验证。另外,我提出的非常具体的一点是,我想了解如何将登录的 Windows AD 帐户传递到用于授权的服务中,而不必要求用户在登录表单中专门输入他们的凭据。以下问题没有解决我的问题。

How to configure ASP.NET Core application to use windows authentication?

最佳答案

在客户端,您是否尝试在发送请求之前设置 withCredentials: true

我会创建一个 Angular 拦截器并在那里设置属性,以便始终设置每个请求。 像这样:

import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable()
export class CustomInterceptor implements HttpInterceptor {
    constructor() { }

    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        request = request.clone({
            withCredentials: true
        });

        return next.handle(request);
    }
}

然后在服务器端检查 User.Identity,它应该让您获得登录用户 AD 的详细信息。

我已经这样做了并且使用 Chrome 我不需要输入任何登录详细信息。它似乎不适用于我的 Firefox,因为您必须在第一次登录。

希望这对您有所帮助。

关于.net - Windows 身份验证 - .NET Core Angular 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48584662/

相关文章:

angular - 如何在 Angular/Jasmine 测试中模拟 Injector 实例?

javascript - Angular 响应式(Reactive)嵌套形式

c# - ASP.NET 核心 : Exclude or include files on publish

c# - Facebook OAuth "Unhandled remote failure. (Correlation Failed.)"

c# - 在最小 API 中将参数设置为 .NET Core 中的可选参数

c# - 仅移动鼠标时内存消耗不断增加

c# - 如何使用Team Foundation的库来计算统一差异?

c# - 为什么感叹号出现在文字前面

c# - 将数据从一种表单传递到另一种表单时出现问题

angular - 使用子组件按钮单击关闭 Kendo Angular 对话框