Mule OAuth2 使用客户端凭据作为 grant_type [英] Mule OAuth2 using Client Credentials as grant_type

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

问题描述

我的需求是使用OAuth2的client_credentials grant_type来获取Mule中的access token.我想实现启用 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.

推荐答案

如果您共享连接器代码会有所帮助.

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/实施+连接+管理

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"
    }

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

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