2015-01-14 94 views
-1

我的要求是使用OAuth2的client_credentials grant_type獲取Mule中的訪問令牌。我想實現一個OAuth啓用的自定義連接器。我無法使用以下配置實現它:使用客戶端憑證作爲grant_type的Mule OAuth2

<XXX-auth2:config name="TestAuth" consumerKey="abc" consumerSecret="1234" doc:name="TestAuth"> 
     <XXX-auth2:oauth-callback-config domain="localhost" localPort="8082" path="callback" remotePort="8082" async="false"/> 
    </XXX-auth2:config> 
    <flow name="testFlow1" doc:name="testFlow1"> 
     <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="testoauth" doc:name="HTTP" /> 
     <XXX-auth2:authorize config-ref="TestAuth" doc:name="TestAuth"/> 
     <logger message="Test Auth output:#[flowVars['tokenId']]" level="INFO" doc:name="Logger"/> 
    </flow> 

我的要求是管理來自批處理作業的受OAuth保護的調用。請建議。

+0

我猜你會在郵件入站屬性'access_token' –

+0

得到tokenId這很好,但我的流量控制甚至沒有達到記錄器組件。沒有任何類型的錯誤或例外。我被困在這裏。 – rst

+0

你能分享你的連接器代碼嗎? –

回答

1

如果您分享您的連接器代碼,這將有所幫助。

但是,如果您使用的是客戶端憑據流,那麼使用@ OAuth2批註可能不是最佳選擇,因爲它使用HTTP GET重定向到服務提供者。

由於此授予類型不需要重定向或回調,因此通常只需將憑據作爲基本身份驗證或在POST主體中傳遞給令牌端點。

你最好不要使用的devkit的連接管理功能和使用HTTP客戶端,以調出您的令牌端點和令牌端點存儲在@Connect方法:

http://www.mulesoft.org/documentation/display/34X/Implementing+Connection+Management

private String token; 
@Connect 
    public void connect(@ConnectionKey String clientKey, @Password String clientSecret) 
      throws ConnectionException 
    { 
     //HTTP client to call token endpoint: 
     //curl -u TestClient:TestSecret https://api.mysite.com/token -d 'grant_type=client_credentials' 
     this.token = "extract from response" 
    } 
+0

謝謝瑞恩。我接受這個答案。但是,如果您可以通過@Connect來了解如何管理令牌並使用過期,這將有所幫助。 – rst

+0

我會將此添加爲一個新問題。 – rst

相關問題