Previously, this is our flow of using GoogleSignInClient
to interact with Google Drive service.
// GoogleSignInClient.silentSignIn() -> GoogleSignInAccount -> Drive object
GoogleSignInClient googleSignInClient = buildGoogleSignInClient();
Task<GoogleSignInAccount> task = googleSignInClient.silentSignIn();
GoogleSignInAccount googleSignInAccount = task.getResult()
Drive drive = getDriveService(googleSignInAccount)
public static GoogleSignInClient buildGoogleSignInClient() {
GoogleSignInOptions signInOptions =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(GOOGLE_DRIVE_CLIENT_ID)
.requestEmail()
.requestScopes(new Scope(DriveScopes.DRIVE_APPDATA))
.build();
return GoogleSignIn.getClient(WeNoteApplication.instance(), signInOptions);
}
private static Drive getDriveService(GoogleSignInAccount googleSignInAccount) {
GoogleAccountCredential credential =
GoogleAccountCredential.usingOAuth2(
MyApplication.instance(), Collections.singleton(DriveScopes.DRIVE_APPDATA)
);
credential.setSelectedAccount(googleSignInAccount.getAccount());
Drive googleDriveService =
new Drive.Builder(
AndroidHttp.newCompatibleTransport(),
new GsonFactory(),
credential
)
.setApplicationName(APPLICATION_NAME)
.build();
return googleDriveService;
}
Now, we are trying to meet the deprecation deadline of GoogleSignInClient
- https://android-developers.googleblog.com/2024/09/streamlining-android-authentication-credential-manager-replaces-legacy-apis.html
Based on https://stackoverflow.com/a/78605090/72437
It seems like I can skip using Credential Manager API (authentication), and jump directly into Authorization
API (authorization)
https://developers.google.com/identity/authorization/android (authorization)
But, what is the replacement for the deprecated googleSignInClient.silentSignIn
?
By having googleSignInClient.silentSignIn
, it enables user to just sign in once, and can keep using Google Drive service without expiry for long period of time.
May I know, how can we achieve equivalent by using Authorization
API?
Thanks.
You can do either of the following two approaches:
I presume you knew these two possibilities and there is something more that you want to accomplish. CredentialManager doesn't have "silentSignIn()" method but I don't think it needs one since it allows a no-prompt interaction for returning users and if there is no such user, it shows the bottomsheet to sign the user in.