User Guide Cancel

OnWSAuthenticate

 

Description

Authenticates the user

History

ColdFusion 10: Added this function

Syntax

OnWSAuthenticate(username, password, connectionInfo)
OnWSAuthenticate(username, password, connectionInfo)
OnWSAuthenticate(username, password, connectionInfo)

Parameters

Parameter Description  
username Name of the user that has to be authenticated.  
password Password for the user.  
connectionInfo

A struct that contains the following keys:

  • Authenticated: {{YES

NO}}

  • ConnectionTime: Connection time stamp.
  • clientID: Unique ID of the client.
    Custom keys are also supported. For example, you can specify the user's role, status, or age.The connectionInfo is shared across all the channels for a given WebSocket client. Also, modifications are persisted across all the subscriptions for that client.

 

Example

The following example uses the function onWSAuthenticate, validates the user, and associates a user role.

Note: For this example to work, ensure that you implement the user-defined functions.

component
{
this.name="websocketsampleapp23";
this.wschannels=[{name="stocks",cfclistener="stocksListener"}];
function onWSAuthenticate(username, password, connectionInfo)
{
//write appropriate logic to fetch user password in funtion checkPassword
If(checkPassword(username) eq password)
{
connectionInfo.authenticated="YES";
//Role is the custom information that you provide
connectionInfo.role= "admin";
return true;
}
else{
connectionInfo.authenticated="NO";
return false;
}
writedump("#connectionInfo#","console");
}
}
component { this.name="websocketsampleapp23"; this.wschannels=[{name="stocks",cfclistener="stocksListener"}]; function onWSAuthenticate(username, password, connectionInfo) { //write appropriate logic to fetch user password in funtion checkPassword If(checkPassword(username) eq password) { connectionInfo.authenticated="YES"; //Role is the custom information that you provide connectionInfo.role= "admin"; return true; } else{ connectionInfo.authenticated="NO"; return false; } writedump("#connectionInfo#","console"); } }
component 
{ 
this.name="websocketsampleapp23"; 
this.wschannels=[{name="stocks",cfclistener="stocksListener"}]; 

function onWSAuthenticate(username, password, connectionInfo) 
{ 
//write appropriate logic to fetch user password in funtion checkPassword 

If(checkPassword(username) eq password) 
{ 
connectionInfo.authenticated="YES"; 
//Role is the custom information that you provide 
connectionInfo.role= "admin"; 

return true; 
} 
else{ 
connectionInfo.authenticated="NO"; 
return false; 
} 
writedump("#connectionInfo#","console"); 

} 

}

Get help faster and easier

New user?