protected virtual void OnAuthenticateClient(ICustomAuthPeer peer, IAuthenticateRequest authRequest, AuthSettings authSettings, SendParameters sendParameters, object state) { try { if (log.IsDebugEnabled) { log.DebugFormat("Authenticating client {0} - custom authentication type: {1}", peer.ConnectionId, authRequest.ClientAuthenticationType); } // when authentication data is provided check if // it is either a byte array or string and convert to byte array // if it's a string value byte[] authData = null; if (authRequest.ClientAuthenticationData != null) { authData = authRequest.ClientAuthenticationData as byte[]; if (authData == null) { var stringData = authRequest.ClientAuthenticationData as string; if (stringData == null) { peer.OnCustomAuthenticationError( ErrorCode.CustomAuthenticationFailed, "Authentication data type not supported", authRequest, sendParameters, state); this.IncrementFailedCustomAuth(); return; } authData = Encoding.UTF8.GetBytes(stringData); } } if (string.IsNullOrEmpty(authRequest.ClientAuthenticationParams) && authData == null && this.isAnonymousAccessAllowed) { // instant callback - treat as anonymous user: if (log.IsDebugEnabled) { log.DebugFormat("Authenticate client: grant access as anonymous user: conId={0}", peer.ConnectionId); } var customResult = new CustomAuthenticationResult { ResultCode = CustomAuthenticationResultCode.Ok }; peer.OnCustomAuthenticationResult(customResult, authRequest, sendParameters, state); return; } // take auth type from auth request (default: custom) var authenticationType = (ClientAuthenticationType)authRequest.ClientAuthenticationType; ClientAuthenticationQueue authQueue; if (this.authenticationServices.TryGetValue(authenticationType, out authQueue) == false) { if (log.IsWarnEnabled) { log.WarnFormat("Authentication type not supported: {0} for AppId={1}/{2}", authenticationType, authRequest.ApplicationId, authRequest.ApplicationVersion); } peer.OnCustomAuthenticationError( ErrorCode.CustomAuthenticationFailed, "Authentication type not supported", authRequest, sendParameters, state); this.IncrementFailedCustomAuth(); return; } var queueState = new AuthQueueState(peer, authRequest, sendParameters, state); authQueue.EnqueueRequest(authRequest.ClientAuthenticationParams, authData, this.AuthQueueResponseCallback, queueState); } catch (Exception ex) { log.Error(ex); } }