如何在FedEx授权API OAuth2.0中获取刷新令牌?

问题描述 投票:0回答:1

我使用 fedex api 进行授权,但找不到任何资源来获取刷新令牌。 任何人都可以提出一些解决方案,这会很有帮助。

这是我现在收到的回复,

网址:/oauth/token

请求正文:

grant_type:client_credentials

client_id:784sdsrfere

客户端秘密:vnjn8741cdsc3e7

范围=openid离线访问

回复:

{

“access_token”:“eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJDWFMtVFAiXSwiUGF5bG9hZCI6eyJjbGllbnRJZGVuB5MQahTTyMPLQnucflB6sc4hk_Gatx3L2Dgs3YkDMV4r3ORiB 2EZKOOIfdKRSBVP5PmBEcYYXvG3bTcqe_X6UTgpxdwBNbNHKZL4",

“token_type”:“承载者”,

“过期时间”:3599,

“范围”:“CXS-TP”

}

fedex
1个回答
0
投票

Fedex 不使用刷新令牌。您必须自己刷新令牌。这是 php 中的示例

`

if (!isset($_SESSION['fedex_access_token']) || isTokenExpired()) {
  $clientID = 'your_client_id';
  $secret = 'your_secret';

  $curl = curl_init("https://apis-sandbox.fedex.com/oauth/token");
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_POST, true);
  curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
    'grant_type' => 'client_credentials',
    'client_id' => $clientID,
    'client_secret' => $secret
  )));
  curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded'
  ));

  $response = curl_exec($curl);

  if (curl_errno($curl)) {
    echo 'cURL error: ' . curl_error($curl);
    exit;
  } else {
    $decoded = json_decode($response);
    $_SESSION['fedex_access_token'] = $decoded->access_token;
    $_SESSION['token_time'] = time();
  }

  curl_close($curl);
}

function isTokenExpired() {
  $expiresIn = 3600;
  if (time() - $_SESSION['token_time'] > $expiresIn) {
    return true;
  }
  else {
    return false;
  }
}

`

© www.soinside.com 2019 - 2024. All rights reserved.