首页 > 解决方案 > Angular 和 IIS Windows 身份验证通信

问题描述

我们正在构建一个当前在localhost:4200上运行的 Angular 应用程序。

我们还有一个在 IIS 上运行的 API(与我们的 Dynamics CRM 后端通信) - localhost:8080/api/api是 IIS 上:8080下的子应用程序)

我们希望我们的 Angular 应用程序能够使用Windows Authentication与我们的 IIS 托管 API 进行通信。

我们尝试像这样使用proxy.config:

const Agent = require('agentkeepalive');

module.exports = {
        '/api': {
            target: 'http://localhost:8080/api',
            secure: false,
            agent: new Agent({
                maxSockets: 100,
                keepAlive: true,
                maxFreeSockets: 10,
                keepAliveMsecs: 100000,
                timeout: 6000000,
                freeSocketTimeout: 90000
            }),
            onProxyRes: proxyRes => {
                let key = 'www-authenticate';
                proxyRes.headers[key] = proxyRes.headers[key] &&
                    proxyRes.headers[key].split(',');
            }
        }
};

然后运行ng serve --proxy-config proxy.config.js

但是我们收到了401 Unauthorized响应。

PS 我们对 API 的所有 HTTP 请求都是POST请求,因此通过我们的 API 对 CRM 中端点的调用看起来像localhost:8080/api/api/getUser

标签: angularapiiisdynamics-crmwindows-authentication

解决方案


推荐阅读