有一个由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请求配置。任何人都可以帮助设置此请求配置。
答案 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元素,但应该可以正常启动。只是忽略它。