【问题标题】:Strava API refresh token doesn't issued after first authorization首次授权后未发布 Strava API 刷新令牌
【发布时间】:2019-03-31 06:15:55
【问题描述】:

也许有人可以帮助我, 我正在尝试在运动员首次使用我的应用程序授权后颁发刷新令牌, Oauth 2.0 在邮递员中运行良好,我可以通过这种方式获取刷新令牌,但不能在我的个人 php 脚本中......我只得到这种 JSON 响应:

{
  "token_type": "Bearer",
  "access_token": "ACCESS_TOKEN",
  "athlete": {
    #{summary athlete representation}
  }
}

但我正在等待一个刷新令牌和一个到期日期,就像 Strava API 文档在这个例子中展示的那样:

{
  "token_type": "Bearer",
  "access_token": "987654321234567898765432123456789",
  "athlete": {
    #{summary athlete representation}
  }
  "refresh_token": "1234567898765432112345678987654321",
  "expires_at": 1531378346,
  "state": "STRAVA"
}

我多次尝试从测试帐户撤消对应用程序的访问,以模拟新的身份验证请求,但我没有找到答案,这是我调用令牌交换 URL 的代码:

<?php 
require 'config.php';
$code = $_GET['code'];


//The url you wish to send the POST request to
$url = "https://www.strava.com/oauth/token";

//The data you want to send via POST
$fields = [
    'client_id'      => $client_ID,
    'client_secret' => $client_secret,
    'code'         => $code,
    'grant_type' => 'authorization_code'
];

//url-ify the data for the POST
$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

//execute post
$result = curl_exec($ch);
echo $result;
print_r(curl_error($ch))
?>

PS:Oauth 2.0 在邮递员中运行良好,我可以通过这种方式获取刷新令牌,但在我的个人 php 脚本中却不行...

感谢您的帮助。

【问题讨论】:

  • 调用https://www.strava.com/oauth/authorize?client_id=YOUR_CLIENT_ID&amp;redirect_uri=YOUR_REDIRECT_URI&amp;response_type=code&amp;scope=YOUR_SCOPE时使用哪些范围参数?
  • 嗨,谢谢回复,我找到了解决方案,但你是对的,它是一个范围参数,我提供了一个错误的范围,并且使用 scope=read_all&amp;scope=activity:read_all,它可以完美运行。
  • 如果您使用旧范围(例如 view_private),您会收到一个没有 expires_at 信息的访问令牌(永久令牌),该令牌将在 2019 年 10 月 15 日之前有效 (developers.strava.com/docs/oauth-updates/…)
  • forever token ... 2019 年 10 月 15 日到期,我想我不会使用它,并在开发应用程序时考虑刷新令牌系统。非常感谢
  • strava 在迁移说明中称它们为永久令牌! ;)

标签: php api oauth-2.0 refresh-token strava


【解决方案1】:

终于找到了解决办法,是范围参数,我提供的范围有误,而且是scope=read_all&amp;scope=activity:read_all, it works perfectly

【讨论】:

    猜你喜欢
    • 2021-09-10
    • 2016-10-13
    • 1970-01-01
    • 2020-05-30
    • 2021-08-19
    • 2014-03-26
    • 1970-01-01
    • 2018-08-21
    • 2017-12-25
    相关资源
    最近更新 更多