I am developing a corporate application in which we use the People API Directory APi, however, I always need to auto-check from a specific user, since I cannot receive data using a service account. How can I get the data of the domain users using a service account?
How can I get the data of the domain users using a service account?
Asked Answered
Hi there @MaximBezmen ! Unfortunately, I don't understand your question about studying it. When you say «I always need to auto-check from a specific user, since I cannot receive data using a service account» I don't understand the operation at hand, could you please clarify it? –
Goulet
I want to log in using the service account when accessing the api to get the open domain profile. However, I cannot request this information using a service account. You need to log in with the data of a real user. –
Oblivion
Thank you for the clarification. To better help you, please share the code that you are using so we all can take a look. –
Goulet
There is no code since I rejected this solution. And I use it for a real user. The user logs into Google with his data and I receive a token and subsequently use it. In general, in Google horror, the documentation for novice developers is very difficult and clear, examples are used for desktop applications ((( –
Oblivion
I am glad that you found a solution to this problem. For better documentation, could you please describe the solution that you used in an answer? –
Goulet
I used this code for connection google API.
public class DirectoryService {
@Value("${service.account.email}")
private String SERVICE_ACCOUNT_EMAIL;
@Value("${service.account.pk.file.path}")
private String SERVICE_ACCOUNT_PKCS12_FILE_PATH;
public Directory getDirectoryService(String userEmail){
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
Directory service = null;
try {
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(Collections.singleton(DirectoryScopes.ADMIN_DIRECTORY_USER_READONLY))
.setServiceAccountUser(userEmail)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
service = new Directory.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential).build();
} catch (GeneralSecurityException e){
log.error("Responding \"GeneralSecurityException in Google API.\" in method getDirectoryService().");
throw new BadRequestException("GeneralSecurityException in Google API.");
}catch (IOException e){
log.error("Responding \"Not connection with Google API.\" in method getDirectoryService().");
throw new BadRequestException("Not connection with Google API.");
}
return service;
}
}
Directory directory = directoryService.getDirectoryService(email);
Users response = directory.users().list()
.setDomain("domain.com")
.setViewType("domain_public")
.setMaxResults(500)
.execute();
© 2022 - 2024 — McMap. All rights reserved.