Access Denied for password reset page I am trying to redirect user to edit profile page after accessing the password reset link, code looks like 

function mymodule_reset_menu_alter(&amp;$items) {
  // Drupal's default behavior is to show the user a log-in form before
  // their user profile.  We replace this item to skip the uneccesary step.
  $items['user/reset/%/%/%'] = array(
    'title' =&gt; 'Account settings',
    'access callback' =&gt; 'simple_pass_reset_pass_reset_access',
    'access arguments' =&gt; array(2, 3, 4),
    'page callback' =&gt; 'test',
    'page arguments' =&gt; array(2, 3, 4),
    'type' =&gt; MENU_CALLBACK,
  );

}

function test($uid, $timestamp, $hashed_pass, $option = NULL) {
  global $user;
  // Show the user edit form instead of silly one-time login form.
  $account = user_load($uid);
  $user = $account;
  $token = drupal_random_key();
  $_SESSION['pass_reset_' . $user-&gt;uid] = $token;
  drupal_goto('user/' . $user-&gt;uid . '/edit', array('query' =&gt; array('pass-reset-token' =&gt; $token)));
 }


while test() is callback for menu 'user/reset/%/%/%'.

The issue is when the user access the link for first time user gets "Access Denied" for second time user successfully redirects to edit profile page with password reset option. I think issue must be in the way the token is generated as it is the only thing which changes, but have no clue on how to fix this.
Drupal has an option to just login using the user reset link. When you add /login after the reset link the user is logged in directly and redirected to their their profile page.