1

我正在尝试使用 Doorkeeper gem 来保护我的 API。

我的代码如下所示:

初始化程序/doorkeeper.rb

Doorkeeper.configure do
  resource_owner_authenticator do
    current_user || warden.authenticate!(:scope => :user)
  end

  default_scopes :public # if no scope was requested, this will be the default
  optional_scopes :admin, :write

  enable_application_owner :confirmation => false
end

以下是我用来连接我的 API 的命令:

RestClient.post 'http://localhost:3000/oauth/token', {
  grant_type: 'client_credentials',
  client_id: '26b8e5c92367d703ad35a2fc16b14dc93327a15798068ccba473aa2e3d897883',
  client_secret: 'b16079915cdc20b5373f1601e31cece5a84274f772cfd89aec12c90fd110775e'
}

... 和 ...

RestClient.get 'http://localhost:3000/api/v1/videos', { 'Authorization' => 'Bearer <token_from_previous_request>' }

哪个工作正常,但我的问题是,返回的 Token 对象有一个空resource_owner_id参数(在创建令牌时,此列未填充到数据库中)。你知道我在做什么错吗?我一直在关注这些教程:

4

1 回答 1

2

客户端凭据流“与资源所有者无关”(https://github.com/applicake/doorkeeper/wiki/Client-Credentials-flow),所以我认为未设置 resource_owner_id 是正确的。

于 2014-02-27T00:22:39.783 回答