2017-05-03 1 views
0

일부 서비스를 연결/사용하려면 mule을 사용하고 있습니다. 인증은 OAuth2 클라이언트 자격 증명입니다. 토큰을 새로 고치는 가장 좋은 방법은 무엇입니까? 한 가지 방법은올바른 방법 Mule OAuth2 클라이언트 자격 증명 새로 고침 토큰

refreshTokenWhen="#[message.inboundProperties['http.status'] == 401]" 

같은 http.status을 확인 할 수 있지만,이 토큰을 새로 고치려면 한 번 실패 때문에 나는 매우 행복하지 않다. 만료 시간을 기준으로 토큰을 새로 고치는 방법이 있습니까? 내 샘플 코드 : 노새의 chache 범위가있다

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:oauth2="http://www.mulesoft.org/schema/mule/oauth2" xmlns:http="http://www.mulesoft.org/schema/mule/http" 
    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.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
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/oauth2 http://www.mulesoft.org/schema/mule/oauth2/current/mule-oauth2.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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> 
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="${remote.host}" port="${remote.port}" basePath="${remote.path}" doc:name="HTTP Request Configuration"> 
    <oauth2:client-credentials-grant-type clientId="${clientid}" clientSecret="${clientSecret}" tokenManager-ref="Token_Manager_Config"> 
     <oauth2:token-request tokenUrl="${remote.tokenUrl}" refreshTokenWhen="#[message.inboundProperties['http.status'] == 401 ]"> 
      <oauth2:token-response accessToken="#[json:access_token]" expiresIn="#[json:expires_in]"/> 
     </oauth2:token-request> 
    </oauth2:client-credentials-grant-type> 
</http:request-config> 
<oauth2:token-manager-config name="Token_Manager_Config" doc:name="Token Manager Config"/> 

답변

0

, 당신은 캐시 범위에 gettoken 흐름을 유지할 수 있으며 캐시 된 토큰을 사용합니다 그때까지 당신이 만료 시간을 지정할 수 있습니다 때 이제까지 그것을 이 토큰이 만료되면 토큰 흐름을 가져오고 캐시에 새 토큰을 저장합니다.

샘플 코드 :
https://docs.mulesoft.com/mule-user-guide/v/3.7/cache-scope

: 아래 링크에서

<ee:object-store-caching-strategy name="Caching_Strategy" doc:name="Caching Strategy"> 
    <managed-store storeName="myManagedStore" maxEntries="1" entryTTL="${token.expiretime}" expirationInterval="${token.expireinterval}"/> 
</ee:object-store-caching-strategy>  

<ee:cache cachingStrategy-ref="Caching_Strategy" doc:name="Cache"> 
    <flow-ref name="getTokenFlow" doc:name="getTokenFlow"/> 
</ee:cache> 

확인, 추가 설명서

관련 문제