google-auth-library-java
google-auth-library-java copied to clipboard
Request: add migration explanation from the old com.google.api.client.googleapis.auth.oauth2.GoogleCredential class
I've noticed the webpage of this repository doesn't explain how to leave the previous one : https://googleapis.dev/java/google-api-client/latest/com/google/api/client/googleapis/auth/oauth2/GoogleCredential.html
Is your feature request related to a problem? Please describe. Yes, I can't find the appropriate functions that match the previous ones. There is no documentation.
Describe the solution you'd like To have such explanation.
Describe alternatives you've considered Maybe write it on the old repository ?
I requested this here for the sample I've found, but it hasn't been updated for a very long time. I can't find a similar sample by Google
Additional context The code I use (here) is very similar and based on what I've found of using the repository to reach the old API, here.
Would be very appreciated if you could tell me at least for these cases how to use them, or provide a nice sample that provides the same thing, of reaching People API.
Here's a more updated code of what I use: https://stackoverflow.com/q/67500479/878126
I was following this official auth guide to work with google directory api and got into deprecated GoogleCredential issue as well. In order to use GoogleCredentials instead of deprecated one to authenticate I did:
// Replaced GoogleCredential builder with GoogleCredentials
GoogleCredentials credentials = GoogleCredentials
.fromStream(new FileInputStream("PATH_TO_CREDENTIALS.JSON"))
.createScoped(DirectoryScopes.MY_SPECIFIC_DIRECTORY_SCOPE_ENUM)
.createDelegated("IMPERSONATED_ACCOUNT_EMAIL");
credentials.refreshIfExpired();
// Now as old builder was returning different type - initialized HttpRequestInitializer
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(impersonated);
// Passed requestInitializer to Directory api Builder
Directory service = new Directory.Builder(httpTransport, jsonFactory, null).setHttpRequestInitializer(requestInitializer).build();
// Rest of it is just using Directory service in this case
Hope this helps
@hmerdok The code I wrote seems to be more dependent (example is PeopleService.Builder
) , but I hope what you wrote could help. I've set a reminder to check if indeed this helps
@hmerdok How do I do this on Android though? How can I reach the json file there? I don't think it's really in the APK, no? And what's "DirectoryScopes.MY_SPECIFIC_DIRECTORY_SCOPE_ENUM" ?