我想使用充当某种代理的Node.js构建服务器。连接到我的服务器的客户端使用NTLMv2进行身份验证(没有机会更改此身份),但是我的服务器应连接到的上游服务器需要Kerberos令牌。
因此,我的问题非常简单:如何使用Node.js将NTLMv2提供的信息转换为Kerberos令牌?到目前为止,在npm上,我已经找到了用于NTLMv2身份验证的模块,但是我可能需要以某种方式与Windows进行对话,以将用户的NTLMv2数据转换为该用户的令牌。
关于此的任何提示,如何解决此问题?
我正在尝试为使用 NTLM 身份验证的服务器实现一个 SOAP 客户端。我使用的库(依赖于 ntlm-auth 的 requests-ntlm2)通过标准库的 hashlib 实现了 NTLM 协议核心的 MD4 算法。
虽然hashlib似乎支持MD4:
>>> import hashlib
>>> hashlib.algorithms_available
{'md5-sha1', 'md4', 'shake_128', 'md5', 'blake2s', 'sha3_512', 'ripemd160', 'sha512', 'mdc2', 'blake2b', 'sha3_256', 'sha3_224', 'sha512_224', 'sha1', 'sha384', 'sha256', 'sha224', 'whirlpool', 'sha512_256', 'sha3_384', 'shake_256', 'sm3'}
>>>
Run Code Online (Sandbox Code Playgroud)
我系统中的 openssl 库也是如此:
(victory) C:\code\python\services>openssl
help:
[...]
Message Digest commands (see the `dgst' command for more details)
blake2b512 blake2s256 md4 md5
mdc2 rmd160 sha1 sha224
sha256 sha3-224 sha3-256 sha3-384
sha3-512 sha384 sha512 sha512-224
sha512-256 shake128 shake256 sm3 …
Run Code Online (Sandbox Code Playgroud) 我从 Visual Studio 模板创建了一个全新的 WebAPI 项目。目标框架netcoreapp3.1
。我已经使用windows 身份验证对其进行了配置。我使用 NTLM 配置在 Postman 中创建了一个请求来调用我的 API。当我调试我的应用程序并通过 Postman 调用请求时,我收到以下错误:
IIS 10.0 Detailed Error - 401.1 - Unauthorized
我的创业班:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace WebApplication1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. …
Run Code Online (Sandbox Code Playgroud) windows-authentication postman asp.net-core-webapi ntlm-authentication
有关设置的一些上下文:
我们正在从NTLM切换到Kerberos(协商),以在各种.NET工作负载(例如IIS托管的Web API或简单的.NET命令行程序)之间进行服务到服务的身份验证。
对于从客户端到服务器的任何调用,中间都有一个API网关。我们在网关中有一些自定义逻辑,用于执行身份验证和强制执行Kerberos(使用NTLM票证拒绝协商标头)。正常的客户端-服务器流如下所示:
现在,为了不做大的改变,我们能够(在网关中)基于来自(C)的请求的原始目的地(应该是大致的主机名)配置发生Kerberos检查的请求和(S)的端口。
此设置可以正常工作,但偶尔会出现一个难以复制的问题:
klist get HTTP/spn-of-G
,即使冒充完全相同的用户,也可以从(C)执行a 并接收正确的Kerberos票证(C)通常以我的问题是:是否有其他可能的方法可以解决这种情况,而无需重新启动服务器?
我已经尝试过但没有成功的事情:
iisreset
。但是我已经看到了这个问题,例如(C)是每15分钟运行一次完成的C#命令行程序。ipconfig /flushdns
klist purge
使用powershell脚本对所有登录会话执行)我曾尝试使用 Android 的 DownloadManager apis 进行下载,但未能成功。
这是我的示例代码,它返回给我下载失败。
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
DownloadManager dm = (DownloadManager) MainActivity.this.getSystemService(MainActivity.this.DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
Run Code Online (Sandbox Code Playgroud) NtlmAuthenticator
一段时间以来, of似乎RestSharp
已被弃用。某处提到的设置方法setting.UseDefaultCredentials = true;
也不可用。
那么我该如何使用NTLM
or Kerberos
withRestSharp
呢?
和不!我不能说我想使用的其他程序LDAP
或OAuth2.0
任何您认为合适的程序。我有一个程序说:“我有一个 API,你可以授权LDAP/Kerberos
,然后你就可以获取数据!” 我不是该 API 的程序员。
有谁知道如何使用较新版本的 RestSharp 获取我的数据,还是我必须返回到旧版本?
c# rest windows-authentication restsharp ntlm-authentication
TLDR;我有几乎相同的控制器,它们仅通过使用async
/ await
(当然还有Task
)而存在实质性差异。非异步版本按预期返回当前用户的用户名,但async
等效版本不会。
我想发现的是
注意:我无法针对 ASP.NET Core 源进行调试,因为尚未授予运行权限Set-ExecutionPolicy
(这似乎是构建解决方案所必需的)
这有效:
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Baffled.API.Controllers
{
[Authorize]
[ApiController]
[Route("[controller]")]
public class IdentityController : ControllerBase
{
private readonly string userName;
public IdentityController(IHttpContextAccessor httpContextAccessor)
{
userName = httpContextAccessor?.HttpContext?.User.Identity?.Name;
}
[HttpGet]
public IActionResultGetCurrentUser()
{
return Ok(new { userName });
}
}
}
Run Code Online (Sandbox Code Playgroud)
这并不能正常工作:
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Baffled.Services;
namespace Baffled.API.Controllers
{ …
Run Code Online (Sandbox Code Playgroud) c# windows-authentication asp.net-core asp.net-core-webapi ntlm-authentication
我正在 .net core 2.1 上运行一个应用程序。我通过已成功生成 WcfServiceClient 的连接服务添加了 wsdl Web 服务。
使用Basic Autorization 时,它工作正常。
这是我用于调用 helloword soap 方法的类:
public string HellowWorld(string input)
{
string wsRes = null;
try
{
var service = new WorkerProcessServiceClient();
var url = $"http://ServerUrl/Directory/WsName.svc";
UriBuilder uriBuilder = new UriBuilder(url);
service.Endpoint.Address = new EndpointAddress(uriBuilder.Uri);
service.ClientCredentials.UserName.UserName = Username;
service.ClientCredentials.UserName.Password = Password;
using (OperationContextScope scope = new OperationContextScope(service.InnerChannel))
{
HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] =
"Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(service.ClientCredentials.UserName.UserName
+ ":"
+ service.ClientCredentials.UserName.Password));
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = …
Run Code Online (Sandbox Code Playgroud) 我计划将现有项目的 Cypress 版本从 6.9.1 更新到 12.6.0。
目前,我们正在导航到网页并在 before() 挂钩中使用 ntlm-auth 登录。之后,网页保持打开状态,可用于接下来的所有测试。
在最新的赛普拉斯版本中,似乎在每个测试用例之后都会清除并关闭页面,据我所知,这是拥有更好的测试用例所需的行为。
但是,在最新的 Cypress 版本中,有没有一种方法可以在 before hook 中导航到网页,或者在第一个测试中,将页面保持打开状态,然后在第二个测试用例中与其交互并导航到同一页面的其他部分、保持页面打开等?
现有的代码结构如下所示:
before(() => {
cy.ntlm(
['<url>'],
<username>,
<password>
);
cy.visit(<url>);
});
it('Test 1', () => {
cy.contains('something').click();
});
it('Test 2', () => {
cy.get('#something').type('{enter}');
});
Run Code Online (Sandbox Code Playgroud)
我尝试在 before 钩子中使用 cy.session() 保存会话,我的想法是在下一个测试中恢复会话/页面,但我不确定这是否是正确的方法。