当使用这样的 URL 请求访问 token 时(客户端凭据作为授权类型):
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"
}
刷新 token 丢失,知道为什么会这样吗?
config.yml 中的我的 FOSOAuthServerBundle:
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
更新
客户端实体调用父实体中的构造函数(位于 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();
}
}
最佳答案
Florent 是对的,client_credentials
默认情况下不应包含刷新 token 。然而,它包含在我正在使用的旧版本中,这就是我感到困惑的原因。
如果可能的话,我建议使用授权类型authorization_code
或password
。如果您确实需要公开 client_credentials
的刷新 token ,我想您可以扩展/覆盖 OAuth2
类并通过调用覆盖方法 grantAccessTokenClientCredentials
父级并从返回的结果中删除 'issue_refresh_token' => false
。
您可以通过将以下内容放入 services.yml 来覆盖 OAuth2
(只要您的 bundle 将“FOSOAuthServerBundle”作为父项):
parameters:
fos_oauth_server.server.class: YourNS\YourBundle\Service\YourOauth2
关于symfony - 使用 FOSOAuthServerBundle 获取刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28432403/