Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
.gif)
| Previous | Next |
IWMSAuthenticationCallback.OnAuthenticateComplete (C#)
The OnAuthenticateComplete method is implemented by the server and called by the plug-in to report the result of the authentication process.
Syntax
Parameters
AuthResult
Member of the WMS_AUTHENTICATION_RESULT enumeration type that contains the result of the authentication process. This must be one of the following values.
| Value | Description |
| WMS_AUTHENTICATION_SUCCESS | Notifies the server that authentication has succeeded. |
| WMS_AUTHENTICATION_DENIED | Notifies the server that authentication has been denied. |
| WMS_AUTHENTICATION_CONTINUE | Notifies the server that the authentication process is not complete, and that the server must request more data from the user. |
| WMS_AUTHENTICATION_ERROR | Notifies the server that an error occurred during the authentication process. |
ChallengeBlob
object containing a binary large object (BLOB). This value is only relevant when the AuthResult parameter contains WMS_AUTHENTICATION_CONTINUE. The server passes the BLOB, unaltered, to the client. If you are creating a custom authentication plug-in, the value you supply is specific to the type of authentication process that the plug-in implements. For example, a Digest Authentication plug-in passes the realm to the client, but an anonymous authentication plug-in does not pass a value.
Context
object containing a value defined by the server to identify which call to IWMSAuthenticationContext.Authenticate the plug-in is responding to when it calls OnAuthenticateComplete. You must pass this value back unaltered.
Return Values
This method does not return a value.
If this method fails, it throws an exception.
| Number | Description |
| 0x80070057 | Context is null. |
| 0x80070057 | Context is an unknown type. |
| 0x80070057 | Context is could not be queried by the server. |
| 0x80070057 | The server could not obtain the authentication context. |
Remarks
The server calls the IWMSAuthenticationContext.Authenticate method to authenticate a client. The plug-in calls the OnAuthenticateComplete method to send the results of the authentication process to the server.
Example Code
// This sample implementation of the Authenticate method
// uses a digest authentication scheme.
public void Authenticate(
object ResponseBlob,
IWMSContext pUserCtx,
IWMSContext pPresentationCtx,
IWMSCommandContext pCommandContext,
IWMSAuthenticationCallback pCallback,
object Context)
{
string AUTH_QOP = "auth";
string AUTH_REALM = "RealmName";
Encoding Enc = Encoding.Unicode;
string strNonce = GenerateNonce();
byte[] Response;
byte[] Challenge = Enc.GetBytes("");
try
{
Response = (byte[])ResponseBlob;
if( Response.Length == 0 )
{
// The client requested authentication; prepare the
// challenge response to send to the client.
Challenge = Enc.GetBytes("realm=\"" + AUTH_REALM +
"\",qop=\"" + AUTH_QOP +
"\",nonce=\"" + strNonce +
"\",charset=utf-8,algorithm=MD5-sess");
m_Result =
WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_CONTINUE;
}
else
{
// The client has responded to the authentication
// challenge; verify the client credentials.
IWMSContext CommandReq;
string strResponse;
string strUserName;
string strRealm;
string strURI;
string strCNonce;
string strNonceCount;
string strChalResponse;
string strCommandName;
string strUserHash;
string strA1Hash;
string strA2Hash;
string strDigestHash;
bool bOK;
strResponse = Enc.GetString(Response);
SplitResponse(strResponse, out strUserName, out strRealm,
out strURI, out strCNonce, out strNonceCount,
out strChalResponse);
pCommandContext.GetCommandRequest(out CommandReq);
CommandReq.GetStringValue("@ WMS_COMMAND_NAME", 153,
out strCommandName,
Convert.ToInt32(
WMS_CONTEXT_OPTIONS.WMS_CONTEXT_GET_PROPERTY_STRING_BY_REFERENCE));
// Retrieve the user hash from the user database.
strUserHash = GetUserHash(strUserName);
strA1Hash = GetHash(strUserHash + ":" +
strNonce + ":" + strCNonce);
strA2Hash = GetHash(strCommandName + ":" + strURI);
strDigestHash = GetHash(strA1Hash + ":" + strNonce +
":" + strNonceCount + ":" +
strCNonce + ":" + AUTH_QOP +
":" + strA2Hash);
// If the computed digest hash is equal to the
// client response, the user can be authenticated.
if( strDigestHash == strChalResponse )
{
bOK = LogonUser("media_client", "", "password",
LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
out m_hToken);
if( bOK )
m_Result =
WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_SUCCESS;
else
m_Result =
WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_ERROR;
}
else
{
m_Result =
WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_DENIED;
}
}
}
catch(Exception e)
{
// TODO: Handle exceptions.
}
finally
{
// Report the results of the authentication
// challenge to the server.
pCallback.OnAuthenticateComplete(m_Result, Challenge, Context);
}
}
Requirements
Reference: Add a reference to Microsoft.WindowsMediaServices.
Namespace: Microsoft.WindowsMediaServices.Interop.
Assembly: Microsoft.WindowsMediaServices.dll.
Library: WMSServerTypeLib.dll.
Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.
See Also
| Previous | Next |