Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleCredential deprecation

We want to implement Google OAUTH to play nicely with our web-app based credentials. Flow starts on UI side, which shows user consent screen, and then we obtain a code. That code is then sent to our java based back-end to get refresh token.

At the moment we use this approach:

 private Analytics getAnalytics(String refreshToken) throws Exception {

        NetHttpTransport httpTransport =
                GoogleNetHttpTransport.newTrustedTransport();

        JsonFactory jsonFactory =
                JacksonFactory.getDefaultInstance();

        return new Analytics.Builder(
                httpTransport,
                jsonFactory,
                new GoogleCredential.Builder()
                        .setTransport(httpTransport)
                        .setJsonFactory(jsonFactory)
                        .setClientSecrets(clientId, clientSecret)
                        .build()
                        .setRefreshToken(refreshToken)
        ).build();
    }

The problem in above is that GoogleCredential is deprecated. What is they non-deprecated way to do this?

We are using following lib:

com.google.apis.google-api-services-analytics:v3-rev20190807-1.30.10
like image 465
NenadP Avatar asked Nov 23 '25 18:11

NenadP


1 Answers

  • Google Credential is not fully deprecated, it depends on the library you are using (com.google.auth:google-auth-library-oauth2-http:0.17.1 should still work)

  • An any case, as mentioned here the non-deprecated way is to use Google Auth Library for Java

  • There are samples for different ways to build the credentials - depending on your use case.

like image 69
ziganotschka Avatar answered Nov 27 '25 00:11

ziganotschka