Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6eeb3827 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

fix(auth): preserve Play session during failed token refresh

parent 1f109690
Loading
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -29,5 +29,10 @@ interface StoreAuthenticator {

    suspend fun logout()

    suspend fun refreshAfterReset(): StoreAuthResult {
        logout()
        return login()
    }

    suspend fun isStoreActive(): Boolean
}
+4 −0
Original line number Diff line number Diff line
@@ -138,6 +138,10 @@ class PlayStoreAuthenticator @Inject constructor(
        playStoreStoredAuthPolicy.clearPersistedAuth()
    }

    override suspend fun refreshAfterReset(): StoreAuthResult {
        return refreshLogin()
    }

    /**
     * Bootstrap new Play auth explicitly from a login mode instead of reading persisted user state.
     */
+3 −4
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ class PlayStoreStoredAuthPolicy {
            }

            is PlayStoreAuthValidationResult.InvalidAuth -> {
                clearRejectedAuthAndBootstrapState()
                clearRejectedBootstrapState()
                Resolution.RefreshRequired
            }

@@ -114,11 +114,10 @@ class PlayStoreStoredAuthPolicy {

    suspend fun clearPersistedAuth() {
        playStoreAuthStore.saveAuthData(null)
        clearCachedValidation()
        clearRejectedBootstrapState()
    }

    suspend fun clearRejectedAuthAndBootstrapState() {
        playStoreAuthStore.saveAuthData(null)
    suspend fun clearRejectedBootstrapState() {
        playStoreAuthStore.saveAasToken("")
        clearCachedValidation()
    }
+3 −3
Original line number Diff line number Diff line
@@ -109,8 +109,8 @@ class PlayStoreTokenRefreshHandler : TokenRefreshHandler {
            }

            val failure = authResult.toAuthError(AuthStore.PLAY_STORE)
            if (shouldEvictPersistedAuth(failure)) {
                playStoreStoredAuthPolicy.clearRejectedAuthAndBootstrapState()
            if (shouldInvalidateBootstrapState(failure)) {
                playStoreStoredAuthPolicy.clearRejectedBootstrapState()
            }
            Timber.e("Play Store token refresh failed: %s", failure.describe())
            AuthResult.Failure(failure)
@@ -129,7 +129,7 @@ class PlayStoreTokenRefreshHandler : TokenRefreshHandler {
        lastSuccessfulRefreshTimestamp = monotonicClockMs()
    }

    private fun shouldEvictPersistedAuth(error: AuthError): Boolean {
    private fun shouldInvalidateBootstrapState(error: AuthError): Boolean {
        return error is AuthError.InvalidToken
    }

+1 −5
Original line number Diff line number Diff line
@@ -154,11 +154,7 @@ class AuthSessionRepositoryImpl @Inject constructor(
            PersistedLoginIntent.NONE -> AuthSession.Unauthenticated
            PersistedLoginIntent.OPEN_SOURCE -> AuthSession.OpenSourceSession
            PersistedLoginIntent.PLAY_ANONYMOUS ->
                if (authData == null) {
                    AuthSession.Unauthenticated
                } else {
                AuthSession.PlayStoreSession(PlayStoreLoginMode.ANONYMOUS)
                }

            PersistedLoginIntent.PLAY_GOOGLE ->
                if (authData == null) {
Loading