symfony - 使用 FOSOAuthServerBundle 获取刷新 token

标签 symfony oauth-2.0 access-token fosoauthserverbundle

当使用这样的 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_codepassword。如果您确实需要公开 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/

相关文章:

php - Symfony2 - Doctrine2 QueryBuilder WHERE IN ManyToMany 字段

java - OAuth2 多个单用户多重登录

c# - 检测到多个匹配标记?

facebook - 如何在收到访问 token 后解释 oauth expires=4 位代码

angularjs - 如何在 Angular 应用程序中存储身份验证 token

php - wkhtmltopdf - libfontconfig.so.1 : cannot open shared object file

php - 如何在Doctrine2中查询WHERE = 'value from a related Entity'

forms - Symfony2 选择形式 split 成 Twig

.net - Postman 客户端凭据流与 Azure AD 保护资源

azure - 生成不记名 token 时签名无效