Using the google-auth-library-java to get a new access token from client secret and refresh token

336 Views Asked by At

Currently, I am using the following code snippet to use as a credential for accessing the Gmail API on Java / Kotlin.

val credentials = GoogleCredential.Builder()
                    .setClientSecrets(clientSecrets)
                    .setJsonFactory(GsonFactory.getDefaultInstance())
                    .setTransport(GoogleNetHttpTransport.newTrustedTransport())
                    .build()
                    .apply {
                        this.refreshToken = refreshToken
                        refreshToken()
                    }

This is currently working, however, the GoogleCredential class is deprecated. Is there a non-deprecated version of accomplishing the same thing? I have tried to find the equivalent but having no luck looking through Google API docs so far.

I have access to the client secrets (in a downloaded .json file) and the refreshToken retrieved on the last authorization flow.

0

There are 0 best solutions below