I want to interface with a REST API of a website (in EXCEL VBA) that requires authentication , using either a digital certificate (.PFX
file) (NTLM authentication), or using the Windows Domain authentication (Kerberos & Negotiate Authentication).
The latter is preferred, but I don't know how to do either, and I was hoping someone could share code on how to do either of these authentication. I can't use other methods of authentication (basic for example) because it's not supported.
Currently I am using VBA-Web (github:VBA-tools:VBA-Web
), and I have managed to interface with the api, but in a very weird way. I tracked the network calls from Chrome to the website, and noticed that it adds the cookies to the header of every call. Hence in my requests, I add:
webrequest.SetHeader "Cookie", "server.com.au=35558896564.55846.54545; SDASESSION=AQISFCwMasdffczd6afASFVHfgfgsdf%2BG35FsE%3D%40AAJTSwAJSDFSDTkMw%3D%3D%23; amlbcookie=07; JSESSIONID=000f:19pcqj2d1; server2.com.au=484566584.454584.41545"
However, this is obviously annoying and not user-friendly - as I have to find the cookies every time I want to use my excel vba code.
Furthermore, after tracking the network calls of the authentication in Chrome, I noticed that it goes through various redirections, collecting all the cookies as it gets redirected. During one particular call, it does a "negotiate"
authentication.
VBA-Web seems to be based off WinHTTP
, so I have looked around and I was really lost in how to interface with WinHTTP
(or WinINet, etc.) to do these authentication. I've looked at the setCredentials
method Link, but I'm not sure what the username and password would be for NTLM or Negotiate?
Alternatively, I've tried to use the digital certificate instead, but since I have a PFX file, I have no idea how to use it directly. I've seen Link but I'm not entirely sure where my certificate is stored after installing the PFX. I choose Personal during the installation, so does that mean it's in LOCAL_MACHINE\Personal ? More importantly I don't know what the subject name is.
The Microsoft documentation is either in C++
or JScript
, so that doesn't help me either.
So If I'm able to authenticate and get the cookies, then the rest should be fine. How would I do this with any of the two methods of authentication, in Excel, using VBA?
P.S I hope my question is clear. Feel free to ask for clarification. All the answers I found reverts to Basic Authentication but I can't do that. I would share with you the website I'm trying to interface with, but it's on the intranet.