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 (Visual Basic .NET)
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 Sub Authenticate(ByVal ResponseBlob As Object, _
ByVal pUserCtx As IWMSContext, _
ByVal pPresentationCtx As IWMSContext, _
ByVal pCommandContext As IWMSCommandContext, _
ByVal pCallback As IWMSAuthenticationCallback, _
ByVal Context As Object) _
Implements IWMSAuthenticationContext.Authenticate
Dim AUTH_QOP As String = "auth"
Dim AUTH_REALM As String = "RealmName"
Dim Enc As Text.Encoding = Text.Encoding.Unicode
Dim strNonce As String = GenerateNonce()
Dim Response As Byte()
Dim Challenge As Byte()
Try
Response = ResponseBlob
If Response.Length = 0 Then
' The client requested authentication; prepare the
' challenge response to send to the client.
Challenge = Enc.GetBytes("realm=" & Chr(34) & _
AUTH_REALM & Chr(34) & _
",qop=" & Chr(34) & _
AUTH_QOP & Chr(34) & _
",nonce=" & Chr(34) & _
strNonce & Chr(34) & _
",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.
Dim CommandReq As IWMSContext
Dim strResponse As String
Dim strUserName As String
Dim strRealm As String
Dim strURI As String
Dim strCNonce As String
Dim strNonceCount As String
Dim strChalResponse As String
Dim strCommandName As String
Dim strUserHash As String
Dim strA1Hash As String
Dim strA2Hash As String
Dim strDigestHash As String
Dim bOK As Boolean
strResponse = Enc.GetString(Response)
SplitResponse(strResponse, strUserName, strRealm, strURI, _
strCNonce, strNonceCount, strChalResponse)
pCommandContext.GetCommandRequest(CommandReq)
CommandReq.GetStringValue("@ WMS_COMMAND_NAME", 153, _
strCommandName, _
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 Then
bOK = LogonUser("media_client", "", "password", _
LOGON32_LOGON_NETWORK, _
LOGON32_PROVIDER_DEFAULT, _
m_hToken)
If bOK Then
m_Result = _
WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_SUCCESS
Else
m_Result = _
WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_ERROR
End If
Else
m_Result = _
WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_DENIED
End If
Challenge = Enc.GetBytes("")
End If
Catch e As Exception
m_Result = WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_ERROR
Finally
' Report the results of the authentication
' challenge to the server.
pCallback.OnAuthenticateComplete(m_Result, Challenge, Context)
End Try
End Sub
string GetHash(string strIn)
{
Encoding Enc = Encoding.ASCII;
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bytInPtr = Enc.GetBytes(strIn);
byte[] bytMD5Ptr = md5.ComputeHash(bytInPtr);
string strHash = BitConverter.ToString(bytMD5Ptr);
strHash = strHash.Replace("-", "").ToLower();
return strHash;
}
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 |