'token mismatch' error using own authentication plugin

Hi, 

I'm making a plugin to automaticalli authenticate users from another app into Elgg. I created a plugin that read the other app cookie and database. It hooks the function from mod/own_auth/start.php

register_elgg_event_handler('init','system','own_auth_init');

and uses this code to make the auth:

if ($user = authenticate($login,$pass)) 

$result = login($user);

It works OK, but when I try to make any action with an auto-authenticated user, the system shows a 'token mismatch' error and no action is made.

What is missing in the own_auth_init function?