2014-08-29 64 views
3

我們使用Apigee使用client_credentials OAuth 2授權流程來請求持有人令牌。按照specApigee似乎不支持OAuth 2規範,是否有原因?

4.4.2. Access Token Request 

    The client makes a request to the token endpoint by adding the 
    following parameters using the "application/x-www-form-urlencoded" 
    format per Appendix B with a character encoding of UTF-8 in the HTTP 
    request entity-body: 

    grant_type 
     REQUIRED. Value MUST be set to "client_credentials". 

如果我們打個電話但我們得到了如下的錯誤:

{"ErrorCode" : "invalid_request", "Error" :"Required param : grant_type"} 

看來,使用Apigee送我們到grant_type作爲查詢參數。

這是爲什麼?由於Apigee處理OAuth 2的方式,我們有Apigee的客戶無法使用他們選擇的語言使用OAuth庫,並且很高興知道是否存在設計問題。

另外,它似乎不支持grant_type在帖子正文中,並使用基本身份驗證發送ID和密鑰。

回答

0

原來你不需要發送grant_type作爲查詢參數。您的GenerateAccessToken策略中有一個接收變量的元素<GrantType>。舉例來說,我可以使用以下命令:

<OAuthV2 name="GenerateAccessToken"> 
    <DisplayName>GenerateAccessToken</DisplayName> 
    <FaultRules/> 
    <Properties/> 
    <!-- This policy generates an OAuth 2.0 access token using the password grant type --> 
    <Operation>GenerateAccessToken</Operation> 
    <!-- This is in millseconds --> 
    <ExpiresIn>1800000</ExpiresIn> 
    <Attributes/> 
    <SupportedGrantTypes> 
    <GrantType>password</GrantType> 
    </SupportedGrantTypes> 
    <GenerateResponse enabled="false"> 
    <Format>FORM_PARAM</Format> 
    </GenerateResponse> 
    <GrantType>user.grant_type</GrantType> 
    <UserName>request.header.username</UserName> 
    <PassWord>request.header.password</PassWord> 
</OAuthV2> 

在這個例子中,grant_type傳遞作爲user.grant_type。但user.grant_type可以是任何東西 - 頭,查詢參數,形式參數,甚至硬編碼的值。通過這種方式,您(開發人員)在grant_type中提供了最大的靈活性。

+1

工程很好,非常感謝! – Michael 2014-09-01 07:14:55

0

你可以粘貼你正在做的確切的API調用(顯然你應該混淆密鑰和祕密)?

我想了解當你說「Apigee」時你說的什麼 - 它可能意味着API BAAS(https://api.usergrid.com)或您使用API​​服務定義的代理,並附加了OAuth 2策略或其他內容?

+0

您好格雷格,這是我們附加了一個OAUthV2策略來生成訪問令牌的代理。現在我期待在政策,我認爲作爲@我們的政策有akoo1010可能是正確的: ' request.queryparam.grant_type' 裏面。我會嘗試他的建議,並會回覆。謝謝 – Michael 2014-09-01 06:31:31

相關問題