2015-02-10 146 views
3

當使用這樣的URL(客戶端憑證交付式)的訪問令牌問:獲取刷新令牌FOSOAuthServerBundle

http://api.local/app_dev.php/oauth/v2/token?client_id=<client_id>&client_secret=<secret>&grant_type=client_credentials 

我得到以下JSON響應:

{ 
access_token: "XXXXXXXXXXX", 
expires_in: 3600, 
token_type: "bearer", 
scope: "user" 
} 

刷新令牌缺失,任何想法爲什麼這可能是?

我FOSOAuthServerBundle在config.yml:

fos_oauth_server: 
    db_driver: orm 
    client_class:  Acme\ApiBundle\Entity\Client 
    access_token_class: Acme\ApiBundle\Entity\AccessToken 
    refresh_token_class: Acme\ApiBundle\Entity\RefreshToken 
    auth_code_class:  Acme\ApiBundle\Entity\AuthCode 
    service: 
     user_provider: platform.user.provider 
     options: 
      supported_scopes: user 

UPDATE

的客戶實體使得父實體的構造函數的調用(位於FOSOAuthServerBundle):

namespace Acme\ApiBundle\Entity; 

use FOS\OAuthServerBundle\Entity\Client as BaseClient; 
use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity 
*/ 
class Client extends BaseClient 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    public function __construct() 
    { 
     parent::__construct(); 
    } 
} 

回答

2

Florent是對的,client_credentials默認情況下不應該包含刷新標記。然而,它包含在我正在使用的舊版本中,這就是我困惑的原因。

如果可能的話,我會建議去撥款類型authorization_codepassword。如果您確實需要爲client_credentials公開一個刷新令牌,我想您可以擴展/覆蓋OAuth2類,並通過調用父級並從返回的結果中除去'issue_refresh_token' => false來覆蓋方法grantAccessTokenClientCredentials

您可以通過將以下在services.yml覆蓋OAuth2(只要你的包有「FOSOAuthServerBundle」作爲一個父):

parameters: 
    fos_oauth_server.server.class: YourNS\YourBundle\Service\YourOauth2 
+0

我已經更新了有關客戶實體的信息。 – rfc1484 2015-02-10 15:26:29

+0

我的意思是在數據庫中,檢查你的客戶端表,你正在使用的ID,列allowed_grant_types(一個序列化數組),包含refresh_token? – 2015-02-10 15:44:07

+0

它存在於序列化數組中,但它的值爲空。 – rfc1484 2015-02-10 16:13:56

2

使用client_credentials刷新令牌的問題是可選的(請參閱RFC6749#section-4.4.3):不應包含刷新令牌。

這不是一個錯誤,而是這個包的正常行爲。

+0

但是,當我創建客戶端時,我也要求刷新令牌授予類型。即使它是可選的,這應該不夠嗎?我用來創建客戶端的命令:'php app/console acme:oauth-server:client:create --redirect-uri =「http://api.local/authorize」--grant-type =「authorization_code」 - -grant-type =「password」--grant-type =「refresh-token」--grant-type =「token」--grant-type =「client_credentials」 – rfc1484 2015-02-10 17:04:00