未接收到刷新令牌auth 2.0



你好,我是新手,正在使用这个库PHP auth 2.0这似乎是使用auth 2.0的一个很好的解决方案。我正在尝试生成刷新令牌,我可以接收它。下面是我的代码:

    OAuth2Autoloader::register();
    // $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
    $storage = new OAuth2StoragePdo(array('dsn' => $this->dsn, 'username' => $this->username, 'password' => $this->password));
    // Pass a storage object or array of storage objects to the OAuth2 server class
    $server = new OAuth2Server($storage,array('always_issue_new_refresh_token' => true,
    'refresh_token_lifetime'         => 2419200,));
    // Add the "Client Credentials" grant type (it is the simplest of the grant types)
    $server->addGrantType(new OAuth2GrantTypeClientCredentials($storage));
    $server->addGrantType(new OAuth2GrantTypeRefreshToken($storage));

这是请求:

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"http://localhost/eventapp/index.php/oauth/handle");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "grant_type=client_credentials&client_id=ID&client_secret=SECRET");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result=curl_exec($curl);
curl_close ($curl);
$result=get_object_vars(json_decode($result));
print_r($result);
有谁能帮我一下吗?请指导我,我在这里做错了什么?
$grantType = new OAuth2GrantTypeRefreshToken($storage, array(
    'always_issue_new_refresh_token' => true
));

刷新令牌授予类型有如下配置:

always_issue_new_refresh_token是否在令牌请求成功时发出新的刷新令牌

Default: false

默认为false,你必须让它为真。

也点击这里

示例请求

$ curl -u TestClient:TestSecret https://api.mysite.com/token -d 'grant_type=password&username=bshaffer&password=brent123'

访问令牌将包含一个刷新令牌

{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"expires_in":3600,
"token_type": "bearer",
"scope":null,
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",

}

最新更新