【问题标题】:OAuth2 callback: redirect after getting an access token by authenticating a codeOAuth2回调:通过验证代码获取访问令牌后重定向
【发布时间】:2014-06-17 18:52:00
【问题描述】:

看看这个google client api for php example

我注意到这部分代码:

/************************************************
  If we have a code back from the OAuth 2.0 flow,
  we need to exchange that with the authenticate()
  function. We store the resultant access token
  bundle in the session, and redirect to ourself.
 ************************************************/
if (isset($_GET['code'])) {
  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();
  $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

问题是我没有收到重定向 (header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));)。事实上,你可以删除它,一切似乎都很好。那么,为什么会出现呢?

【问题讨论】:

    标签: php oauth-2.0 google-oauth claims-based-identity google-api-php-client


    【解决方案1】:

    你没有得到哪个重定向?

    代币交换代码是标准 Oauth2 流程(所谓的“授权授予”)的一部分。您可以在此处阅读有关交换的信息:https://docs.auth0.com/protocols#4(或在此处的规范中:https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-31#section-4.1)。规范有点难解析。

    code 发布到您网站上的特定位置 (/callback),因为它通常是在 IdP 中注册的固定位置。之后的任何其他重定向通常是将用户发送到他们最初想要登陆的实际资源。或者干脆到(经过身份验证的)家。例如:如果用户想转到https://yoursite/someplace,但他们需要进行身份验证,则可能会发生这种情况:整个流程发生,然后他们被重定向到/someplace

    【讨论】:

      猜你喜欢
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 2017-12-10
      • 2013-10-23
      • 2016-09-15
      • 2016-10-05
      相关资源
      最近更新 更多