2016-09-03 2 views
0

こんにちは私は初心者で、このライブラリを使用しています php auth 2.0 これはauth 2.0を使用するための良い解決策と思われます。私はそれを受け取ることができるリフレッシュトークンを生成しようとしています。ここに私のコードは次のとおりです。ここでリフレッシュトークン認証を受信して​​いません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); 

誰もがこれで私を助けることができますか?私がここで間違っていることを教えてください?

+0

リフレッシュトークンが含まれていますhere

例リクエスト

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

をご確認ください。そうすれば、例外を監視するのが非常に簡単になります。私は – khakishoiab

+0

@khakishoiabには、私はアプリで実際のIDとシークレットを使用していないのです@khakishoiabタイムアウトの問題 – asfandahmed1

+0

トークンを更新していないアクセストークンを受け付けております – khakishoiab

答えて

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

のリフレッシュトークン許可タイプは、以下の構成があります。デフォルトで

Default: false 

ので、成功したトークンの要求に応じて新たなリフレッシュトークンを発行するかどうかを always_issue_new_refresh_token

をその偽、あなたをそれを真実にしてください。

はまた、アクセストークンは、その後、私はあなたが郵便配達残りのクライアントを使用するように要求する

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

}

+0

'$ server = new OAuth2 \ Server($ storage、array( 'always_issue_new_refresh_token' => true、 'refresh_token_lifetime' => 2419200、 ))' – khakishoiab

関連する問題