首页 文章

Google Drive使用服务帐户与Salesforce集成

提问于
浏览
0

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

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

这是我的auth uri适用于oAuth(但要求您登录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;
}

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

1 回答

  • 0

    创建命名凭据时,会有一个名为“身份类型”的字段 . 您想选择Named Principal . 然后,您使用Google用户名/密码(或您为集成设置的帐户)对应用进行身份验证 . 然后,所有其他用户与您的指定凭据进行交互 .

    或者,您不能将命名凭据与Auth Provider一起使用,而是编写代码以将服务帐户凭据与JWT一起使用 .

相关问题