SAMPLE: Progress Uses IAuthenticate to Bind to Secured Web Page

ID: Q156905


The information in this article applies to:


SUMMARY

The Progress.exe sample from the ActiveX SDK, Internet Client SDK, and MSDN Online Web Workshop demonstrates how to use a URL moniker to asynchronously bind to data from a remote site on the Internet or an intranet. This Knowledge Base sample extends the original Progress by handling the case where authentication is required to access secured data.


MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

Progress.exe
For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online Services


For additional information, please see the following article in the Microsoft Knowledge Base:
Q156904 FIX: Returning User Name and Password from IAuthenticate Fails
Handling authentication requests from a URL moniker requires that the URL moniker host implement a bind status callback object which exposes both the IBindStatusCallback interface and the IAuthenticate interface. The sample uses multiple inheritance to expose these interfaces on the same object.

The IAuthenticate interface consists of a single method, Authenticate. The sample implements IAuthenticate::Authenticate as follows:

STDMETHODIMP CBindStatusCallback::Authenticate( 
    HWND __RPC_FAR *phwnd,
    LPWSTR __RPC_FAR *pszUsername,
    LPWSTR __RPC_FAR *pszPassword)
{
	TCHAR pszDlgUser[255];
	WCHAR wszDlgUser[255];
	TCHAR pszDlgPassword[255];
	WCHAR wszDlgPassword[255];

	if (!phwnd || !pszUsername || !pszPassword)
	{
		return E_INVALIDARG;
	}

	*phwnd = g_hwndDlg;

	// If dialog controls have valid user & pass, use that
	HWND hWndUser = ::GetDlgItem(g_hwndDlg, IDC_USERNAME);
	HWND hWndPassword = ::GetDlgItem(g_hwndDlg, IDC_PASSWORD);
	::GetWindowText(hWndUser, pszDlgUser, 1024);
	::GetWindowText(hWndPassword, pszDlgPassword, 1024);
	if (NULL != pszDlgUser && NULL != pszDlgPassword && '\0' != pszDlgUser[0])
	{
		MultiByteToWideChar(GetACP(), 0, pszDlgUser, -1, wszDlgUser, 255);
		MultiByteToWideChar(GetACP(), 0, pszDlgPassword, -1, wszDlgPassword, 255);
		*pszUsername = wszDlgUser;
		*pszPassword = wszDlgPassword;
	}
	else
	{
		*pszUsername = NULL;
		*pszPassword = NULL;
	}

	return S_OK;

} 

When the URL moniker attempts to bind to the object specified in the call to CreateURLMoniker, it determines whether or not the object is secured. If the object is secured, the URL moniker queries the bind status callback object for IAuthenticate. The URL moniker queries for IAuthenticate through the IBindStatusCallback interface pointer registered with the bind context used in the binding operation.

The implementation of Authenticate above retrieves the username and password from the dialog controls and returns them to the URL moniker if the username is non-NULL. Otherwise, the sample returns a valid window handle. The URL moniker uses this handle as the parent window handle in a call to the InternetErrorDlg WININET API. InternetErrorDlg presents the user with a dialog box requesting a user name and password required to access the secured data.

To demonstrate how a URL moniker requests authentication information from its host, perform the following steps:
  1. Launch the Internet Information Server (IIS) Service Manager utility.


  2. Edit the properties of the web site you are going to test Progress against. In the security options, disable all authentication options other than basic authentication.


  3. Build the revised Progress sample.


  4. Run the revised Progress sample and specify as an command-line argument the HTTP address of an HTML page on the Web Server configured in steps 1 and 2.


  5. Click the Go button to commence the download.


  6. A network password dialog box appears. Enter the user name and password of an account that has access to the machine running the IIS.


The HTML page specified in step 4 is displayed in the sample dialog box.

Additional query words: URLMON IBSC


Keywords          : kbIE300 kbIE400 kbIE401 kbURLMon kbIE500 AXSDKUrlMon 
Version           : 1.0
Platform          : WINDOWS 
Issue type        : 

Last Reviewed: April 29, 1999