<![CDATA[ How to trigger OnWebAuthentication - My Forums]]> https://forums.modx.com/thread/?thread=99218 <![CDATA[How to trigger OnWebAuthentication]]> https://forums.modx.com/thread/99218/how-to-trigger-onwebauthentication#dis-post-536579
I've written the following plugin to authenticate users against a third party database. The System Events OnWebAuthentication is enabled.

if ($modx->event->name == 'OnWebAuthentication') {
    
        $ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,'{urlhere}');
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
	curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
	$output = curl_exec($ch);
	curl_close($ch);		
		
	if($output == '1')
	{
               $modx->event->output(true);
	}else{
	       $modx->event->output(false);
	}

}



I'm using the standard login Package but my plugin isn't being triggered? how do I trigger it?]]>
flyersun Jan 04, 2016, 09:44 AM https://forums.modx.com/thread/99218/how-to-trigger-onwebauthentication#dis-post-536579
<![CDATA[Re: How to trigger OnWebAuthentication]]> https://forums.modx.com/thread/99218/how-to-trigger-onwebauthentication#dis-post-536601 ]]> lokamaya Jan 04, 2016, 04:15 PM https://forums.modx.com/thread/99218/how-to-trigger-onwebauthentication#dis-post-536601 <![CDATA[Re: How to trigger OnWebAuthentication]]> https://forums.modx.com/thread/99218/how-to-trigger-onwebauthentication#dis-post-536599
Try putting this at the top and check the error log in the Manager:

$modx->log->(modX::LOG_LEVEL_ERROR, "Plugin Executed");


Does your cURL call return '1' exactly when the user is valid? If so it would be safer to use === '1'.

For the end of your code, instead of the if statement, try this (note the underscore on _output):

$modx->event->_output =  ! empty($output);
return '';


If it works, try changing it to this safer version:

$modx->event->_output =  $output === '1';
return '';


You may have to do it this way:

$modx->event->_output =  trim($output) === '1';
return '';




]]>
BobRay Jan 04, 2016, 03:58 PM https://forums.modx.com/thread/99218/how-to-trigger-onwebauthentication#dis-post-536599