【发布时间】:2018-07-03 23:17:56
【问题描述】:
我们有一个新的应用程序,它使用 ReactJS 作为前端,后端是 .NET Core API。
一项要求是授权 Windows 登录用户使用 Active Directory。
.NET Core API 将执行授权部分。
我们在 .NET Core API 中使用了以下代码,但它返回了运行 .NET Core API 的 App-Pool 的 ID。我们尝试将 API 设置为启用 Windows 身份验证,但效果不佳。
dynamic userIdentity = WindowsIdentity.GetCurrent();
dynamic userPrincipal = new WindowsPrincipal(userIdentity);
string Admin = _configuration["AppUserRoles:Admin"];
result = userPrincipal.IsInRole(Admin);
我已将代码更改为以下内容:
dynamic userIdentity = WindowsIdentity("UserID");
dynamic userPrincipal = new WindowsPrincipal(userIdentity);
string Admin = _configuration["AppUserRoles:Admin"];
result = userPrincipal.IsInRole(Admin);
我们需要将 UserID 从 ReactJS 传递到 API 层。
在 ReactJS 中我尝试了以下方法:
var path = require('path');
var userName = process.env['USERPROFILE'].split(path.sep)[2];
var loginId = path.join("domainName",userName);
但这在 ReactJS 中不起作用。
有没有办法我们可以在 React JS 中获取 Windows 登录 ID 并将其传递给 API 层进行授权?
【问题讨论】:
-
也许看看helloJS?支持windows认证
标签: reactjs api .net-core authorization reactjs.net