2017-09-14 116 views
0

我能夠使用oAuth創建Google Drive集成到Salesforce中。但我的問題是,該應用程序重定向用戶登錄到谷歌。我希望它以編程方式登錄,這樣每個用戶都可以自動登錄爲Google Drive用戶,而無需額外的步驟。我覺得唯一的方法是使用Google雲端硬盤中的服務帳戶。除了查看文檔外,我沒有看到如何在Apex中進行設置。下面是其中顯示了文檔的Java:Google Drive與Salesforce集成使用服務帳戶

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

這裏是我的身份驗證的URI是OAuth作品(但需要你登錄到谷歌:

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' + 
     '&[email protected]' + 
     '&access_type=offline'; 

    authenticationURI = authuri; 
} 

}

再到授權只需調用此方法:

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

任何人知道如何進行身份驗證而不被重定向到谷歌登錄?

回答

0

當您創建一個名爲憑據時,有一個稱爲身份類型的字段。 你想選擇名字校長。然後,使用您的Google用戶名/密碼(或您爲集成設置的帳戶)對應用進行身份驗證。所有其他用戶隨後會與您指定的憑證進行交互。

或者,您不能在Auth提供程序中使用Named Credential,而是編寫代碼以使用JWT的Service Account憑據。