如何调用令牌端点并将令牌保存在 WSO2 Micro Integrator 4.2.0 中

问题描述 投票:0回答:1

我正在尝试几个用例。 其中之一是调用具有 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&amp;client_id=$1&amp;client_secret=$2</format>
        <args>
            <arg value="xxxx"/>
            <arg value="yyyy"/>
        </args>
    </payloadFactory>

但这不起作用。有什么想法吗?

感谢您的意见!

问候

wso2 wso2-esb wso2-api-manager wso2-enterprise-integrator
1个回答
0
投票

如果您找到答案,请与我们分享 谢谢

© www.soinside.com 2019 - 2024. All rights reserved.