Mule 4 HTTP请求客户端访问OAuth 2端点

时间:2019-01-02 13:51:09

标签: mule mule-studio mule-esb

有一个由OAuth2保护的外部服务(例如“ https://external-service.com/service”)。我有客户ID(让我们说“ 123_my_client_id”),秘密ID(“ 324_mysecret”)和访问令牌URL(比如说“ https://access-token.com/access-token”)向我返回令牌。
我想通过Mule 4 Http Request访问此服务。我遵循了这个https://docs.mulesoft.com/connectors/http/http-authentication#oauth2-client-credentials,但是找不到任何可行的解决方案。

这可以在Mule 3.9中完成。但仍然无法为Mule 4设置此http请求配置。任何人都可以帮助设置此请求配置。

1 个答案:

答案 0 :(得分:3)

为了将请求身份验证迁移到Mule 4,配置现在属于http:request-connection组件,并且HTTP身份验证配置必须放在http:authentication组件中。这适用于支持的所有身份验证类型:基本,摘要,NTLM和OAuth2。

在提供的链接中的示例中:

    <http:request-config name="HTTP_Request_Configuration"
                     host="some.api.com" port="80" basePath="/api/1.0">
        <oauth:client-credentials-grant-type
            clientId="your_client_id" clientSecret="your_client_secret"
            tokenUrl="http://some.api.com/api/1.0/oauth/token"
            scopes="access_user_details, read_user_files">
        </oauth:client-credentials-grant-type>
    </http:request-config>

更改为以下内容:

    <http:request-config name="HTTP_Request_Configuration">
        <http:request-connection host="some.api.com" port="80">
            <http:authentication>
                <oauth:client-credentials-grant-type
                    clientId="your_client_id" clientSecret="your_client_secret"
                    tokenUrl="http://some.api.com/api/1.0/oauth/token" scopes="access_user_details, read_user_files" />
            </http:authentication>
        </http:request-connection>
    </http:request-config>

Studio可能会抱怨oauth元素,但应该可以正常启动。只是忽略它。