2016-10-11 10 views
0

새로 고침 토큰을 얻으려는 문서 나 샘플 코드를 찾을 수 없으므로 상자 커넥터의 3.0.0.201609093037 버전 (최신 버전)을 사용하고 있습니다. 나는 그것을 얻기 위해 내 자신의 흐름을 썼다.Mule의 Box Connector를 사용하여 refresh_token을 얻는 방법

커넥터를 사용하여 권한 부여 작업을 수행하면 내 의도는 Box API에이 URL (https://api.box.com/oauth2/token)을 요청하여 access_token과 refresh_token을 얻는 것입니다 (여기에서 API 정보를 얻었습니다. https://docs.box.com/reference#token).

문제입니다, 내 흐름이 승인되고 난 access_code을 얻고, 나는 항상이 수신하고 상자에 보내 그것을 사용하고 있습니다 된 후 :

{ 
    "error": "invalid_grant", 
    "error_description": "The authorization code has expired" 
} 

내가 모든 정보를 확인하고 I 이 좋은 것으로 생각, 내가 기대하고있어 응답은 다음과 같습니다

{ 
    "access_token": "T9cE5asGnuyYCCqIZFoWjFHvNbvVqHjl", 
    "expires_in": 3600, 
    "restricted_to": [], 
    "token_type": "bearer", 
    "refresh_token": "J7rxTiWOHMoSC1isKZKBZWizoRXjkQzig5C6jFgCVJ9bUnsUfGMinKBDLZWP9BgR" 
} 

은 그래서 필요하면 토큰을 이러한 속성을 저장하고 새로 고침 할 수 있습니다. 여기

어떻게 내 흐름과 같이 보인다 : 여기

enter image description here

내 XML 정의 : 나는 이미 같은 PARAMS와 POSTMAN을 사용하려고 것을 언급해야

<?xml version="1.0" encoding="UTF-8"?> 

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:tls="http://www.mulesoft.org/schema/mule/tls" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:box="http://www.mulesoft.org/schema/mule/box" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/box http://www.mulesoft.org/schema/mule/box/current/mule-box.xsd 
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd 
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd 
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd 
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd 
http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd"> 
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" protocol="HTTPS"> 
     <tls:context> 
      <tls:key-store type="jks" path="OBKeytore.jks" keyPassword="password" password="password"/> 
     </tls:context> 
    </http:listener-config> 
    <box:config-with-oauth name="Box__OAuth_2_0" clientId="my_client_id" clientSecret="My_secret" doc:name="Box: OAuth 2.0"> 
     <box:oauth-callback-config domain="localhost" localPort="8081" remotePort="8081" path="callback" connector-ref="HTTP_Listener_Configuration"/> 
     <box:oauth-store-config objectStore-ref="_defaultInMemoryObjectStore"/> 
    </box:config-with-oauth> 
    <objectstore:config name="ObjectStore__Connector" partition="BoxAccessToken" persistent="true" doc:name="ObjectStore: Connector"/> 
    <http:request-config name="HTTP_Request_Configuration" host="api.box.com" port="443" basePath="/oauth2/" doc:name="HTTP Request Configuration" protocol="HTTPS"/> 
    <tls:context name="TLS_Context" doc:name="TLS Context"> 
     <tls:trust-store path="OBKeytore.jks" password="password" type="jks"/> 
     <tls:key-store type="jks" path="OBKeystore.jks" keyPassword="password" password="password"/> 
    </tls:context> 
    <flow name="Authorize"> 
     <http:listener config-ref="HTTP_Listener_Configuration" path="/authorize" doc:name="HTTP"/> 
     <box:authorize config-ref="Box__OAuth_2_0" doc:name="Box"/> 
     <flow-ref name="GenerateAcessToken" doc:name="GenerateAcessToken"/> 
    </flow> 
    <flow name="GenerateAcessToken"> 
     <logger message="Acess Token: #[flowVars['_oauthVerifier']]" level="INFO" doc:name="Logger"/> 
     <set-payload value="#[[ 
    'grant_type' :'authorization_code', 
    'code':flowVars['_oauthVerifier'], 
    'client_id':'my_client_id', 
    'client_secret':'my_secret' 
]]" doc:name="Set Payload"/> 
     <http:request config-ref="HTTP_Request_Configuration" path="token" method="POST" doc:name="HTTP"> 
      <http:success-status-code-validator values="200,400"/> 
     </http:request> 
     <object-to-string-transformer doc:name="Object to String"/> 
     <logger message="#[payload]" level="INFO" doc:name="Logger"/> 
     <catch-exception-strategy doc:name="Catch Exception Strategy"> 
      <object-to-string-transformer doc:name="Object to String"/> 
      <logger message="#[payload]" level="INFO" doc:name="Logger"/> 
     </catch-exception-strategy> 
    </flow> 
</mule> 

, 교체 코드 (30 초 동안 유효하다는 것을 알고 있습니다)와 동일한 응답을 얻습니다. 여기

좀 더 많은 정보 :

Anypoint 스튜디오 버전 : 6.1.1 서버 런타임 : A에 대한 설명 3.8.1 EE

답변

1

그것은 HTTP 요청자의의 OAuth 인증 구성 같은 소리해야 할 수 있습니다 상자 사용자에 속하고 리소스에 액세스하려고 뮬 서버는 박스 서버에서 개최됩니다 https://docs.mulesoft.com/mule-user-guide/v/3.8/authentication-in-http-requests

http://mulesoft.github.io/box-connector/3.0.0/apidocs/box-apidoc.html#_oauth_2_0_server_to_server 당신이 그것을 본적이 없다면 가치를 살펴 수 있습니다 예를 들어 상자를 사용하여이 example of managing OAuth tokens.

+0

처음에는 앱을 처음 승인해야하지만, 필요하면 매번 토큰을 새로 고치는 데 Mule 커넥터가 처리합니다. 앱을 다시 시작하지 않으면 문제없이 작업 할 수 있습니다. @catpaws에게 감사합니다. – Edgar