Setting a Credential Manager

An application that provides credentials to the network source must do the following:

  1. Implement a credential manager object that exposes the IMFNetCredentialManager interface.
  2. Before you create the network source, create a new property store.
  3. Set the MFNETSOURCE_CREDENTIAL_MANAGER property on the property store. The value of the property is a pointer to the IMFNetCredentialManager interface.
  4. Pass a pointer to the property store to the source resolver, as described in Configuring a Media Source.

The network sources uses the credential manager to get user credentials. If the network source requires credentials to access a network resource, it calls the application's IMFNetCredentialManager::BeginGetCredentials method. This call starts an asynchronous request to gets the user's credentials. The BeginGetCredentials method can get the credentials either from the credential cache or from the user. Credentials are stored in a credential object. When the operation is complete, the application invokes the callback interface to notify the network source. The network source calls IMFNetCredentialManager::EndGetCredentials to complete the asynchronous operation.

Because this is an asynchronous operation, the application must dispatch the callback at the end of the operation. For step-by-step instructions about writing an asynchronous method, see Writing an Asynchronous Method.

The following example shows how to set the MFNETSOURCE_CREDENTIAL_MANAGER property on the network source.


// Creates a media source from a URL.
//
// Demonstrates how to set a credential manager on the network source.

HRESULT CreateMediaSourceWithCredentialManager(
    PCWSTR pszURL, 
    IMFMediaSource **ppSource
    )
{
    IPropertyStore *pConfig = NULL;

    CCredentialManager *pCredentials = new (std::nothrow) CCredentialManager();

    if (pCredentials == NULL)
    {
        return E_OUTOFMEMORY;
    }

    // Configure the property store.
    HRESULT hr = PSCreateMemoryPropertyStore(IID_PPV_ARGS(&pConfig));

    if (SUCCEEDED(hr))
    {
        PROPERTYKEY key;
        key.fmtid =  MFNETSOURCE_CREDENTIAL_MANAGER;
        key.pid = 0;

        PROPVARIANT var;
        var.vt = VT_UNKNOWN;
        pCredentials->QueryInterface(IID_PPV_ARGS(&var.punkVal));

        hr = pConfig->SetValue(key, var);

        PropVariantClear(&var);
    }

    // Create the source media source.
    if (SUCCEEDED(hr))
    {
        hr = CreateMediaSource(pszURL, pConfig, ppSource);
    }

    SafeRelease(&pConfig);
    SafeRelease(&pCredentials);

    return hr;
}


Related topics

Network Source Authentication

 

 

Show: