【问题标题】:Mule OAuth2 using Client Credentials as grant_typeMule OAuth2 使用客户端凭据作为 grant_type
【发布时间】:2015-01-14 18:26:05
【问题描述】:

我的要求是使用 OAuth2 的 client_credentials grant_type 来获取 Mule 中的访问令牌。我想实现启用 OAuth 的自定义连接器。我无法使用以下配置实现它:

<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 保护调用。请提出建议。

【问题讨论】:

  • 我猜你会在消息入站属性'access_token'中获得tokenId
  • 那很好,但我的流控制甚至没有到达记录器组件。没有任何类型的错误或异常。我被困在这里了。
  • 你能分享你的连接器代码吗?

标签: api oauth mule connector


【解决方案1】:

如果您分享您的连接器代码会有所帮助。

但是,如果您使用的是客户端凭据流,则可能不适合使用 @OAuth2 注释,因为它使用 HTTP GET 重定向到服务提供者。

由于这种授权类型不需要重定向或回调,通常您只需将凭据作为基本身份验证或在 POST 正文中传递到令牌端点。

您最好使用 Devkit 的连接管理功能并使用 http 客户端调用您的令牌端点并将令牌端点存储在 @Connect 方法中:

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

【讨论】:

  • 谢谢瑞恩。我接受这个作为答案。但是,如果您可以了解使用@Connect 管理令牌和到期的方法,将会有所帮助。
  • 我将把它添加为一个新问题。
猜你喜欢
  • 2021-12-22
  • 1970-01-01
  • 2016-09-28
  • 1970-01-01
  • 2012-12-17
  • 1970-01-01
  • 2018-09-15
  • 2023-04-09
  • 2020-12-25
相关资源
最近更新 更多