Skip to content

Commit

Permalink
Bug 1869134 - Don't crash on SyncScopedKeyMissingInServerResponse
Browse files Browse the repository at this point in the history
(cherry picked from commit 1ccd2f1)
  • Loading branch information
bendk authored and rvandermeulen committed Dec 14, 2023
1 parent 9a54b2e commit 00c8268
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ typealias FxaUnauthorizedException = mozilla.appservices.fxaclient.FxaException.
*/
typealias FxaOriginMismatchException = mozilla.appservices.fxaclient.FxaException.OriginMismatch

/**
* Thrown when a scoped key was missing in the server response when requesting the OLD_SYNC scope.
*/
typealias FxaSyncScopedKeyMissingException =
mozilla.appservices.fxaclient.FxaException.SyncScopedKeyMissingInServerResponse

/**
* Thrown when the Rust library hits an unexpected error that isn't a panic.
* This may indicate library misuse, network errors, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import mozilla.components.service.fxa.AccountOnDisk
import mozilla.components.service.fxa.AccountStorage
import mozilla.components.service.fxa.FxaAuthData
import mozilla.components.service.fxa.FxaDeviceSettingsCache
import mozilla.components.service.fxa.FxaSyncScopedKeyMissingException
import mozilla.components.service.fxa.Result
import mozilla.components.service.fxa.SecureAbove22AccountStorage
import mozilla.components.service.fxa.ServerConfig
Expand Down Expand Up @@ -733,7 +734,23 @@ open class FxaAccountManager(
return
}

val accessToken = account.getAccessToken(SCOPE_SYNC)
val accessToken = try {
account.getAccessToken(SCOPE_SYNC)
} catch (e: FxaSyncScopedKeyMissingException) {
// We received an access token, but no sync key which means we can't really use the
// connected FxA account. Throw an exception so that the account transitions to the
// `AuthenticationProblem` state. Things should be fixed when the user re-logs in.
//
// This used to be thrown when the android-components code noticed the issue in
// `asSyncAuthInfo()`. However, the application-services code now also checks for this
// and throws its own error. To keep the flow above this the same, we catch the
// app-services exception and throw the android-components one.
//
// Eventually, we should remove AccessTokenUnexpectedlyWithoutKey and have the higher
// functions catch `FxaSyncScopedKeyMissingException` directly
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1869862)
throw AccessTokenUnexpectedlyWithoutKey()
}
val tokenServerUrl = if (accessToken != null) {
// Only try to get the endpoint if we have an access token.
account.getTokenServerEndpointURL()
Expand Down

0 comments on commit 00c8268

Please sign in to comment.