2015-02-10 160 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