我正在尝试几个用例。 其中之一是调用具有 OAuth2 安全性的端点。为此,我使用了带有 HTTP 端点的呼叫调解器,然后配置如下:
<call>
<endpoint>
<http method="get" uri-template="https://someurl.com/api">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
<authentication>
<oauth>
<clientCredentials>
<clientId>XXX</clientId>
<clientSecret>YYY</clientSecret>
<tokenUrl>https://sometokenendpoint/token</tokenUrl>
<authMode>payload</authMode>
</clientCredentials>
</oauth>
</authentication>
</http>
<property name="Content-Type" scope="transport" value="application/x-www-form-urlencoded"/>
</endpoint>
</call>
但是,如果我想从令牌端点获取令牌并将其保存以供稍后在多个 API 调用的集成流程中使用,该怎么办?无论如何,当我要使用相同的令牌进行多个 API 调用时,感觉没有必要多次调用令牌端点。如您所见,我使用 grant_type=client_credentials 获取令牌。如何为对我的令牌端点的 POST 调用构建正确的正文?
调用令牌端点的正确 CURL 是“curl -L ' https://sometokenendpoint.com/token' -H '内容类型:application/x-www-form-urlencoded' -d 'grant_type=client_credentials' -d 'client_id=XXXXX' -d 'client_secret=YYYY' -k"
我尝试创建一个payloadfactory并将ContentType属性设置为application/x-www-form-urlencoded,如下所示:
<payloadFactory media-type="text">
<format>grant_type=client_credentials&client_id=$1&client_secret=$2</format>
<args>
<arg value="xxxx"/>
<arg value="yyyy"/>
</args>
</payloadFactory>
但这不起作用。有什么想法吗?
感谢您的意见!
问候
如果您找到答案,请与我们分享 谢谢