【问题标题】:Get refresh token with FOSOAuthServerBundle使用 FOSOAuthServerBundle 获取刷新令牌
【发布时间】:2015-04-10 12:41:03
【问题描述】:

当使用这样的 url 请求访问令牌时(客户端凭据作为授权类型):

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"
}

刷新令牌丢失,知道为什么会这样吗?

我在 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();
    }
}

【问题讨论】:

    标签: symfony oauth-2.0 access-token fosoauthserverbundle


    【解决方案1】:

    Florent 是对的,client_credentials 默认不应该包含刷新令牌。但是,它包含在我正在使用的旧版本中,这就是我感到困惑的原因。

    如果可能的话,我建议使用authorization_codepassword 的授权类型。如果您确实需要为client_credentials 公开刷新令牌,我想您可以扩展/覆盖OAuth2 类并通过调用父级并从返回的结果中删除'issue_refresh_token' =&gt; false 来覆盖方法grantAccessTokenClientCredentials

    您可以通过将以下内容放入 services.yml 来覆盖 OAuth2(只要您的捆绑包具有“FOSOAuthServerBundle”作为父级):

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

    【讨论】:

    • 我的意思是在数据库中,检查您的客户端表,对于您正在使用的 id,列 allowed_grant_types(序列化数组)是否包含 refresh_token?
    • 它存在于序列化数组中,但它的值为空。
    • 编辑了我的答案。我使用的是旧版本的FOSOAuthServerBundle,默认情况下会公开refresh_token
    【解决方案2】:

    使用client_credentials 的刷新令牌问题是可选的(请参阅RFC6749#section-4.4.3):不应包含刷新令牌。

    这不是错误,而是此捆绑包的正常行为。

    【讨论】:

    • 但是,当我创建客户端时,我还要求刷新令牌授予类型。即使它是可选的,那还不够吗?我用于创建客户端的命令: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"
    猜你喜欢
    • 2020-09-25
    • 2019-10-26
    • 2015-07-19
    • 2019-05-15
    • 2019-02-25
    • 2022-01-23
    • 2020-02-26
    • 2013-08-23
    相关资源
    最近更新 更多