MuleSoft Google 日历连接器

MuleSoft Google Calendar connector

有什么方法可以使用 google 服务帐户验证 Mule google 日历连接器,这样我就可以避免每次访问弹出窗口。

查看管理 OAuth 令牌,如果您使处理这些持久化的对象存储,那么它将重用访问令牌而不是每次都重定向以进行授权:https://docs.mulesoft.com/mule-user-guide/v/3.4/using-a-connector-to-access-an-oauth-api#managing-oauth-tokens-optional

我找到了解决问题的简单方法

    public void Auth() {
    try {
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
         credential = new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(getConsumerKey())
            .setServiceAccountPrivateKeyFromP12File(new File(getConsumerSecret()))
            .setServiceAccountScopes(Arrays.asList(getScope())).build();

         client = new Calendar.Builder(
                    httpTransport, JSON_FACTORY, credential)
                    .setApplicationName(getApplicationName()).build();

    } 
    catch (Exception e) {

        e.printStackTrace();
    }
}

只需在现有 google 日历代码中包含上述功能,并从代码中删除基于令牌的身份验证。 这对 google.

的服务帐户绝对有效

谢谢