【发布时间】: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