与SSPI的INDY TIdHttp集成安全身份验证问题

时间:2013-02-27 12:01:32

标签: security delphi indy

我正在尝试使用Windows身份验证安全性调用IIS上托管的Web服务。

我正在使用带有INDY 10的Delphi XE和TIdHttp组件。

如果我传入有效的用户名和密码,我可以成功调用Web服务,但我想使用Integrated Security,以便它自动使用来自调用线程的凭据,并且不需要用户手动输入其详细信息。

我在uses子句中包含了IdAuthenticationSSPI,并将http请求调用为:

IdHttp1.Request.BasicAuthentication := False;
IdHttp1.HTTPOptions := [hoInProcessAuth];
// IdHttp1.Request.Username := '...'; // including this works
// IdHttp1.Request.Password := '...'; // including this works

IdHttp1.Get(myURL, myOutputStream);

我的理解是,如果没有凭据传递,它将使用IdAuthenticationSSPI模拟调用线程的用户。

我在atozedsoftware.newsgroups网站上看到了一些建议可能会有这样的评论,但不幸的是我收到了“HTTP / 1.1 401 Unauthorized”。

有人有任何建议吗?

1 个答案:

答案 0 :(得分:3)

根据Remy Lebeau的评论,在修复已知问题之前,看起来这是不可能的。

我已经用另一种方式解决了我的问题,我会在这里发布,以防其他人感兴趣。

首先我导入了WinHTTP类型库(C:\ Windows \ system32 \ winhttp.dll)并将WinHttp_TLB添加到uses子句中。

然后我像这样使用它:

var
    http: IWinHttpRequest;
    url: String;
begin
    url := 'my web service';
    http := CoWinHttpRequest.Create;
    try
        http.SetAutoLogonPolicy(0); // Enable SSO
        http.Open('GET', url, False);
        http.Send(EmptyParam);
        ShowMessage(http.ResponseText);
    finally
        http := nil;
    end;
end;