Skip to content
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

Please update the quickstart guide with an example using google-auth-library-java #7388

Open
SEOguruNL opened this issue Mar 24, 2021 · 1 comment
Labels
priority: p4 type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@SEOguruNL
Copy link

Problem
The example in the quickstart guide 'Running a Search Console App in Java' is still using the deprecated googleapis.auth.oauth2.GoogleCredential. I understand that googleapis.google-auth-library-java.credentials should be used instead.

Solution
I'd like to see an updated example in the quickstart-guide where the google-auth-library-java is used.

Additional context
I've asked this question on several places, but nobody seems to be able to come up with an example.

@Neenu1995 Neenu1995 transferred this issue from googleapis/google-auth-library-java Mar 24, 2021
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 25, 2021
@danoscarmike danoscarmike added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Mar 25, 2021
@haimraman
Copy link

I was missing this documentation as well, what I was able to figurer out from the project README
https://github.com/googleapis/google-auth-library-java#google-auth-library-credentials was this.
Credentials were generated as a service account from https://console.cloud.google.com/
with Enable G Suite domain-wide delegation

  final var accountCredentials = ServiceAccountCredentials.fromStream(new FileInputStream(
                "custom-octagon-abc1234.json"));
        ServiceAccountCredentials serviceAccountCredentials = ServiceAccountCredentials.newBuilder()
                .setClientId(accountCredentials.getClientId())
                .setClientEmail(accountCredentials.getClientEmail())
                .setPrivateKey(accountCredentials.getPrivateKey())
                .setPrivateKeyId(accountCredentials.getPrivateKeyId())
                .setScopes(SCOPES)
                .setServiceAccountUser("[email protected]")
                .setProjectId(accountCredentials.getProjectId())
                .build();

        HttpCredentialsAdapter credentialsAdapter = new HttpCredentialsAdapter(serviceAccountCredentials);
        Gmail service = new Gmail.Builder(GoogleNetHttpTransport.newTrustedTransport(),
                GsonFactory.getDefaultInstance(),
                credentialsAdapter).setApplicationName("My App").build();

        String user = "me";
        final var messagesResponse = service.users().labels().list(user).execute();
        System.out.println(messagesResponse.getLabels().stream().map(Label::getName).collect(Collectors.joining(",\n"))); 

Although it works for me I sill missing official examples and a bit lost between all the token types and when should I use IAM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p4 type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

5 participants