2012-07-20 92 views
3

我试图建立一个与门卫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."} 

你能帮助我理解缺失的是什么吗? 谢谢

+0

任何你想测试这些流程的原因? OAuth流在门卫 – 2012-07-22 06:48:53

+0

中测试得很好我知道,我一直在深入挖掘代码。我仍然必须检查这些功能,因为我的一些逻辑可能会破坏它们。当你得到一个引擎对你来说非常重要的事情时,为主要使用场景构建一些集成测试是一种很好的做法 – 2012-07-23 10:18:29

回答

2

我终于搞定了。我错过了关于OAuth2规范的一个重要方面,客户端必须使用基本身份验证来标识自己。我解决了在帖子前添加它,它工作得很好。

before do 
    page.driver.browser.authorize application.uid, application.secret 
    page.driver.post access_uri, access_params 
    end