小编use*_*495的帖子

ReactJS 和 .NET Core API 中的 windows 授权

我们有一个新应用程序,它以 ReactJS 作为前端,后端是 .NET Core API。

要求是针对 Active Directory 授权 Windows 登录用户。

.NET Core API 将负责授权部分。

我们在 .NET Core API 中使用了以下代码,但它返回 .NET Core API 的应用程序池正在运行的 ID。我们尝试将 API 设置为启用 Windows 身份验证,但效果不佳。

            dynamic userIdentity = WindowsIdentity.GetCurrent();
            dynamic userPrincipal = new WindowsPrincipal(userIdentity);
            string Admin = _configuration["AppUserRoles:Admin"];
            result = userPrincipal.IsInRole(Admin);
Run Code Online (Sandbox Code Playgroud)

我已将代码更改为以下内容:

            dynamic userIdentity = WindowsIdentity("UserID");
            dynamic userPrincipal = new WindowsPrincipal(userIdentity);
            string Admin = _configuration["AppUserRoles:Admin"];
            result = userPrincipal.IsInRole(Admin);
Run Code Online (Sandbox Code Playgroud)

我们需要将 UserIDReactJS 传递到 API 层。

在 ReactJS 中我尝试了以下操作:

            var path = require('path');
            var userName = …
Run Code Online (Sandbox Code Playgroud)

api authorization reactjs .net-core reactjs.net

4
推荐指数
1
解决办法
7444
查看次数

标签 统计

.net-core ×1

api ×1

authorization ×1

reactjs ×1

reactjs.net ×1