【问题标题】:Google Drive Integration with Salesforce Using Service Account使用服务帐户与 Salesforce 集成 Google Drive
【发布时间】:2017-09-18 11:18:53
【问题描述】:

我能够使用 oAuth 在 Salesforce 中创建 Google Drive 集成。但我的问题是,该应用程序将用户重定向到登录谷歌。我希望它以编程方式登录,以便每个用户都以相同的 Google Drive 用户身份自动登录,无需额外步骤。我觉得这样做的唯一方法是使用 Google Drive 中的服务帐户。除了查看文档外,我看不到如何在 Apex 中进行设置。这是显示 Java 的文档:

https://developers.google.com/identity/protocols/OAuth2ServiceAccount#authorizingrequests

这是适用于 oAuth 的我的身份验证 uri(但需要您登录 Google:

global class cAuthURIForApiReq {
global String authenticationURI = '';

public cAuthURIForApiReq(String clientKey, String redirect_uri) {
    String key = EncodingUtil.urlEncode(clientKey, 'UTF-8');
    String uri = EncodingUtil.urlEncode(redirect_uri, 'UTF-8');

    String authuri = 'https://accounts.google.com/o/oauth2/v2/auth?' +
         'client_id=' + key +
         '&response_type=code' +
         '&scope=https://www.googleapis.com/auth/drive' +
         '&redirect_uri=' + uri +
         '&state=security_token%3D138r5719ru3e1%26url%3Dhttps://oauth2-login-demo.example.com/myHome' +
         '&login_hint=jsmith@example.com' +
         '&access_type=offline';

    authenticationURI = authuri;
}

}

然后授权调用这个方法:

 public PageReference driveAuth() {
    PageReference pg = new PageReference(new cAuthURIForApiReq(key, redirect_uri).authenticationURI);
    return pg;
}

有人知道如何以编程方式进行身份验证而不被重定向到谷歌登录吗?

【问题讨论】:

    标签: google-drive-api salesforce apex


    【解决方案1】:

    当您创建命名凭据时,有一个称为身份类型的字段。 您要选择命名主体。然后,您使用您的 Google 用户名/密码(或您为集成设置的帐户)验证应用程序。然后,所有其他用户都像您一样与命名凭据进行交互。

    或者,您不能将命名凭据与身份验证提供程序一起使用,而是编写代码以将服务帐户凭据与 JWT 一起使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-20
      • 2013-07-10
      • 2021-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-20
      相关资源
      最近更新 更多