Reputation: 265
In internet explorer i can set the proxy server. Then, when accessing the internet IE will prompt me for proxy credentials and optionally save them. New instances of IE pick up the credentials.
I can also see the credentials are saved in the Credentials Manager, as a Generic Credential. The name follows a naming convention like Microsoft_WinInet_[proxyserver:port]/[proxyserver.acme.com].
My app uses WinINet. We are currently setting the credentials via InternetSetOption with INTERNET_OPTION_PROXY_USERNAME and INTERNET_OPTION_PROXY_PASSWORD.
But instead I want to tell WinINet to use IE's (or the Credentials Manager) credentials for the current user.
Upvotes: 5
Views: 3003
Reputation: 11
Initialize the use of WinINet functions with predefined proxy parameters from IE like this
HINTERNET hOpen = NULL;
hOpen = InternetOpen(L"XXX", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
...
Upvotes: 1
Reputation: 265
The way to have WinINet use credentials manager credentials is to use the InternetErrorDlg function, like so:
retry:
BOOL fRet = ::HttpSendRequest(hRequest, NULL, 0, NULL, 0);
DWORD dwError = ::GetLastError();
DWORD statusCode(0);
DWORD statusLen = sizeof(DWORD);
DWORD headerIndex = 0;
::HttpQueryInfo(hRequest, HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE,
&statusCode, &statusLen, &headerIndex);
if (statusCode == HTTP_STATUS_PROXY_AUTH_REQ)
{
DWORD dwFlags = FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS |
FLAGS_ERROR_UI_FLAGS_GENERATE_DATA;
DWORD res =::InternetErrorDlg(GetDesktopWindow(), hRequest,
ERROR_INTERNET_INCORRECT_PASSWORD, dwFlags, NULL);
if (res == ERROR_INTERNET_FORCE_RETRY)
goto retry;
else
return false;
}
InternetErrorDlg will return ERROR_INTERNET_FORCE_RETRY if it succeeded in getting credentials (from the CM or by prompting the user).
The FLAGS_ERROR_UI_FLAGS_NO_UI flag (not used above) can be used to avoid showing the dialog that prompts the user for credentials.
Julio
Upvotes: 2