To begin with, I'd implement third-party authentication that way:
In run():
$dispatcher = EventDispatcher::getInstance();
$dispatcher->attachListener(Events::OPERATOR_AUTHENTICATE, $this, 'checkAuth');
And your checkAuth method should looks somehow like that:
public function checkAuth(&$args)
{
$request = $args['request'];
$login = $request->request->get('login');
$password = $request->request->get('password');
$operator = operator_by_login($login);
if ((!$operator || ($operator['vcpassword'] === 'auth_by_remote_service')) && $login && $password) {
// dummy part
// do something and get auth result
// ...
$result = true;
// ...
// end of dummy part
if (!$result) {
return;
}
if (!$operator) {
$operator = create_operator($login, '', '', '', '', '', '');
$operator = operator_by_login($login);
$operator['vcpassword'] = 'auth_by_remote_service';
update_operator($operator);
}
else {
update_operator($operator);
}
$args['operator'] = $operator;
}
Of course it's just a quick'n'dirty concept to illustrate the basic idea.
And if you need an URI related to Mibew, why won't you make use of the very same request object? $request->getUri() will do the job. You'll be able to redirect an operator to the very same page he originally requested.