-
Notifications
You must be signed in to change notification settings - Fork 702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service account: Cannot set user to impersonate using GoogleCredential fromStream #1007
Comments
How are you going about setting the user in the PKCS12 case? |
Hey Wilson, Did you get a response on this issue? |
@abhishek-choudhury No, I never heard anything. I resorted to using the builder with a PKCS12 file. |
@WilsonGiese Thanks for your response Wilson! |
Hi, There is a work around, please have a look at the code below. public GoogleCredential getCredentials(HttpTransport httpTransport, JsonFactory jsonFactory) throws GeneralSecurityException, IOException {
List<String> scopes = new ArrayList<>();
scopes.add(DirectoryScopes.ADMIN_DIRECTORY_USER);
scopes.add(DirectoryScopes.ADMIN_DIRECTORY_USER_READONLY);
InputStream credentialsJSON = ServiceAccountCredentials.class.getClassLoader()
.getResourceAsStream("service_account.json");
GoogleCredential gcFromJson = GoogleCredential.fromStream(credentialsJSON, httpTransport, jsonFactory).createScoped(scopes);
return new GoogleCredential.Builder()
.setTransport(gcFromJson.getTransport())
.setJsonFactory(gcFromJson.getJsonFactory())
.setServiceAccountId(gcFromJson.getServiceAccountId())
.setServiceAccountUser("[email protected]")
.setServiceAccountPrivateKey(gcFromJson.getServiceAccountPrivateKey())
.setServiceAccountScopes(gcFromJson.getServiceAccountScopes())
.build();
} |
JSON all the things! The console will issue JSON by default and make you dig for P12's. Lets go future! Except here. Don't look here. This issue has only been open for a year I guess... |
@netp-dany awesome! i've been looking for hours for an example. aka you're a f*king genius |
Fixed in #1079 |
I'm trying to use a service account to automatically manage/create groups using the Directory API. When I try to use a service account with the credentials in the form of JSON and try to use the GoogleCredential.fromStream(...) call, there does not seem to be a way to set the user, and at least for the Admin API I cannot get calls to work without impersonating a user as I always get Forbidden (403) responses.
Using the GoogleCredential Builder seems to work fine with the PKCS12 formatted key as long as I set the user, but your docs and console seem to recommend to use the JSON formatted credential file.
Have I missed something, or is this functionality not available without using the builder?
The text was updated successfully, but these errors were encountered: