Search code examples
vbaauthenticationpostkerberoswinhttprequest

VBA Kerberos Authentication


I want to send a POST request to a Java servlet with VBA using the Kerberos ticket from the Windows Log In for authentication and then retrieve a JSON response from the servlet. Can I achieve this without using an InternetExplorer object, e.g. using WinHttpRequest?


Solution

  • WinHttpRequest is not an IE object. The above described usecase works perfectly as long as you set up to relax the security permissions. I have implemented a proof of concept last year: Excel, VBA, REST, Tomcat, SPNEGO authentication.

    Stub code:

    Dim winHttp As Object
    Set winHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
    
    winHttp.SetAutoLogonPolicy (0)
    winHttp.Open "GET", "http://..."
    winHttp.send
    
    Dim success As Boolean
    success = winHttp.waitForResponse(5)
    If Not success Then
        Debug.Print "DOWNLOAD FAILED!"
        Exit Sub
    End If
    
    Dim responseText As String
    responseText = winHttp.responseText