【问题标题】:correct way Mule OAuth2 client credentials refresh token正确的方式 Mule OAuth2 客户端凭据刷新令牌
【发布时间】:2017-05-03 13:55:05
【问题描述】:

我正在使用 mule 连接/使用一些服务。身份验证是 OAuth2 客户端凭据。 刷新令牌的最佳方法是什么? 一种方法可能是检查 http.status 像

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

但我对此不太满意,因为刷新令牌应该失败一次。 反正有没有根据过期时间刷新令牌? 我的示例代码:

<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"/>

【问题讨论】:

    标签: oauth-2.0 mule anypoint-studio


    【解决方案1】:

    mule 中有一个 chache 范围,你可以将你的 gettoken 流保持在缓存范围内,你可以指定过期时间,直到那个时间它将使用缓存的令牌,当它过期时,它会调用 get 令牌流,它会将新令牌存储在您的缓存中。

    示例代码:

    <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>
    

    在以下链接查看更多文档:
    https://docs.mulesoft.com/mule-user-guide/v/3.7/cache-scope

    【讨论】:

      猜你喜欢
      • 2017-09-06
      • 1970-01-01
      • 2018-12-14
      • 2019-05-24
      • 2019-01-08
      • 2022-01-26
      • 1970-01-01
      • 2020-02-25
      • 2016-06-01
      相关资源
      最近更新 更多