1

我使用 oauth 将我的网络应用程序连接到 twitter。它工作正常,但我需要定期重新授权应用程序。

我将密钥保存在会话中,但是当用户关闭页面时,这似乎被清除了。

我应该将密钥保存在额外的 cookie 中吗?

function access_token($tmhOAuth) {
  $tmhOAuth->config['user_token']  = $_SESSION['oauth']['oauth_token'];
  $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];

  $code = $tmhOAuth->request(
    'POST',
    $tmhOAuth->url('oauth/access_token', ''),
    array(
      'oauth_verifier' => $_REQUEST['oauth_verifier']
    )
  );

  if ($code == 200) {
    $_SESSION['access_token'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
    unset($_SESSION['oauth']);
    header('Location: ' . tmhUtilities::php_self());
  } else {
    outputError($tmhOAuth);
  }
}
4

1 回答 1

2

您可以将密钥保存在 cookie 中,确保将 cookie 的有效期设置足够长的时间,或者将它们存储在持久性数据库中的时间。

于 2012-11-12T11:52:30.350 回答