2017-09-14 5 views
0

oAuth를 사용하여 Salesforce에 Google 드라이브 통합을 만들 수있었습니다. 하지만 내 문제는 앱이 사용자를 Google에 로그인하도록 리디렉션한다는 것입니다. 프로그램 방식으로 로그인하여 모든 사용자가 별도의 단계없이 자동으로 동일한 Google 드라이브 사용자로 로그인되도록하고 싶습니다. 이 작업을 수행하는 유일한 방법은 Google 드라이브의 서비스 계정을 사용하는 것입니다. 문서를 보는 것 외에는 Apex에서 이것을 설정하는 방법을 알지 못합니다. 여기에 표시되는 문서는 자바 :Google 드라이브와 Salesforce의 통합 서비스 계정 사용

다음

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

OAuth를 작동 (그러나 구글에 로그인하도록 요구 내 인증의 URI입니다 : 다음

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; 
} 

사람 로그인하도록 Google로 리디렉션되지 않고 프로그래밍 방식으로 인증하는 방법을 알고 계십니까?

답변

0

명명 된 자격 증명을 만들면 Identity Type이라는 필드가 있습니다. 명명 된 사용자를 선택하려고합니다. 그런 다음 Google 사용자 이름/비밀번호 (또는 통합을 위해 설정 한 계정)를 사용하여 앱을 인증합니다. 다른 모든 사용자는 귀하와 마찬가지로 명명 된 자격 증명과 상호 작용합니다.

또는 Auth Provider와 함께 Named Credential을 사용할 수없고 대신 JWT에 서비스 계정 자격 증명을 사용하는 코드를 작성할 수 없습니다.