骡子OAuth2用户使用客户端的凭据grant_type [英] Mule OAuth2 using Client Credentials as grant_type

查看:452
本文介绍了骡子OAuth2用户使用客户端的凭据grant_type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是使用的OAuth2的client_credentials grant_type获得在骡子的访问令牌。我想实现一个启用OAuth的自定义连接器。我无法用下面的配置来实现它:

My requirement is to use client_credentials grant_type of OAuth2 to obtain the access token in Mule. I want to implement a OAuth enabled custom connector. I am unable to achieve it using following configuration:

<XXX-auth2:config name="TestAuth" consumerKey="abc" consumerSecret="1234" doc:name="TestAuth">
        <XXX-auth2:oauth-callback-config domain="localhost" localPort="8082" path="callback" remotePort="8082" async="false"/>
    </XXX-auth2:config>
    <flow name="testFlow1" doc:name="testFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082"  path="testoauth" doc:name="HTTP" />
         <XXX-auth2:authorize config-ref="TestAuth" doc:name="TestAuth"/>
        <logger message="Test Auth output:#[flowVars['tokenId']]" level="INFO" doc:name="Logger"/>
    </flow>

我的要求是,以管理从批处理作业的OAuth保护的呼叫。请建议。

My requirement is to manage OAuth protected calls from a batch job. Please suggest.

推荐答案

这将如果您共享您的连接器code帮助。

It would help if you share your connector code.

然而,如果你正在使用客户证书流动,使用@的OAuth2注解可能不走,因为这使用HTTP GET重定向到服务提供商的方式。

However if you are using client-credentials flow, using the @OAuth2 annotations is probably not the way to go as this uses HTTP GET to redirect to the service provider.

由于此批类型不需要重定向或回调,通常你只是凭据传递作为基本身份验证或POST身体令牌端点。

As this grant type doesn't require redirection or callbacks, typically you just pass the credentials in as basic auth or in the POST body to a token endpoint.

您最好使用的devkit的连接管理功能和使用HTTP客户端调用到您的令牌端点和令牌端点存储在@Connect方法:

You're better off using connection management features of Devkit and using a http client to call out to your token endpoint and store the token endpoint in the @Connect method:

http://www.mulesoft.org/documentation/display/34X/Implementing+Connection+Management

private String token;
@Connect
    public void connect(@ConnectionKey String clientKey, @Password String clientSecret)
            throws ConnectionException
    {
        //HTTP client to call token endpoint:
        //curl -u TestClient:TestSecret https://api.mysite.com/token -d 'grant_type=client_credentials'
        this.token = "extract from response"
    }

这篇关于骡子OAuth2用户使用客户端的凭据grant_type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆