没有收到刷新令牌身份验证2.0

时间:2016-09-03 13:50:32

标签: php yii oauth oauth-2.0

您好我是新手并使用此库 php auth 2.0 这似乎是使用auth 2.0的一个很好的解决方案。我正在尝试生成刷新令牌,我可以收到它。这是我的代码:

    OAuth2\Autoloader::register();

    // $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
    $storage = new OAuth2\Storage\Pdo(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 OAuth2\Server($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 OAuth2\GrantType\ClientCredentials($storage));
    $server->addGrantType(new OAuth2\GrantType\RefreshToken($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);

任何人都可以帮我吗?请指导我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

$grantType = new OAuth2\GrantType\RefreshToken($storage, array(
    'always_issue_new_refresh_token' => true
));

刷新令牌授权类型具有以下配置:

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

Default: false

所以默认情况下它是假的,你已经成功了。

同时检查here

示例请求

$ 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",

}

相关问题