4

我正在尝试使用 Doorkeeper 建立一个 OAuth2 提供程序,并且我想测试所有现有的流程,但在第一次尝试时就卡住了。

我正在尝试测试授权代码流。获取授权代码一切正常,但是一旦我尝试获取访问令牌,就会出错。下面提到的是一些步骤。

      describe 'when sends an access token request' do

        let(:access_params) do
          { grant_type:  'authorization_code',
            code:         authorization_code,
            redirect_uri: application.redirect_uri }
        end

        let(:access_uri) { '/oauth/token' }

        before { page.driver.post access_uri, access_params }

        it 'returns valid json' do
          pp page.source
        end

我期待带有最终访问令牌的 json,但我收到了这个错误。我很好地检查了客户端和参数。在我看来一切都很好。

        {"error":"invalid_client","error_description":"Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method."}

你能帮我理解缺少什么吗?谢谢

4

1 回答 1

3

我终于搞定了。我错过了关于 OAuth2 规范的一个重要方面,即客户端必须使用基本身份验证来标识自己。我解决了在发布之前添加它,并且效果很好。

  before do
     page.driver.browser.authorize application.uid, application.secret
     page.driver.post access_uri, access_params
  end
于 2012-07-20T16:10:40.457 回答