How to use user_external_login_register() with user authenticated by token?
It seems a couple of mistakes in your above code.

Your $cs_user array below line should be populated with name instead of lastname

'name' =&gt; $user_info['data']['user']['lastname'] . "_psr",


Also, It seems 2nd line of your function function chapterspot_signon_user_external_login_register($name, $module) is not needed. Because if you Initialize your $account variable with $name then your condition if (!$account) { never comes true and the code written into that if condition will never executed.

You can try two approaches it will work for you:

1) Call Built-in function user_external_login_register($name, $module)  from your custom module.

Example:

user_external_login_register("addweb-solution", "your-custom-module-name");
drupal_goto('/members');


2) You can write your own function as below in your custom module:

function test_user_external_login_register($name, $module){
        $account = user_load_by_name($name);
        // $account = $name;
        if (!$account) {
            $userinfo = array('name' =&gt; $name,
              'pass' =&gt; user_password(),
              'init' =&gt; $name,
              'status' =&gt; 1,
              'access' =&gt; REQUEST_TIME,
            );
            // Register this new user.
            $account = user_save(drupal_anonymous_user(), $userinfo);
            // Terminate if an error occurred during user_save().
            if (!$account) {
              drupal_set_message(t("Error saving user account."), 'error');
              return;
            }
            user_set_authmaps($account, array(
              "authname_{$module}" =&gt; $name,
            ));
        }
        // Log user in.
        $form_state['uid'] = $account-&gt;uid;
        user_login_submit(array(), $form_state);
        drupal_goto('/members');

}


Hope this will helps you.

Thanks!