fix(auth): a password reset signs out Subsonic apps too, and a change can (#8107)
A reset ended every session but left the API key and Subsonic password working, and anyone signed in to the account can make either. So whoever had the account kept it through a Subsonic app after the owner reset the password. The forgotten-password reset and an admin's reset now replace the API key with one nobody holds and clear the Subsonic password. A self-service change keeps Subsonic apps signed in by default, since it would sign out the owner's own apps too. The web and Android password forms gain "Sign out Subsonic apps too", sent as sign_out_subsonic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -82,12 +82,15 @@ data class UpdateProfileRequest(
|
||||
)
|
||||
|
||||
/**
|
||||
* Body for `PUT /api/me/password`. Both fields required.
|
||||
* Body for `PUT /api/me/password`. Both passwords required.
|
||||
* [signOutSubsonic] also ends every Subsonic app's access: the API token and
|
||||
* Subsonic password stop working.
|
||||
*/
|
||||
@Serializable
|
||||
data class ChangePasswordRequest(
|
||||
@SerialName("current_password") val currentPassword: String,
|
||||
@SerialName("new_password") val newPassword: String,
|
||||
@SerialName("sign_out_subsonic") val signOutSubsonic: Boolean = false,
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,9 +30,13 @@ class MeRepository @Inject constructor(retrofit: Retrofit) {
|
||||
UpdateProfileRequest(displayName = displayName, email = email),
|
||||
).toDomain()
|
||||
|
||||
suspend fun changePassword(current: String, next: String) {
|
||||
suspend fun changePassword(current: String, next: String, signOutSubsonic: Boolean = false) {
|
||||
api.changePassword(
|
||||
ChangePasswordRequest(currentPassword = current, newPassword = next),
|
||||
ChangePasswordRequest(
|
||||
currentPassword = current,
|
||||
newPassword = next,
|
||||
signOutSubsonic = signOutSubsonic,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.fabledsword.minstrel.theme.Muted
|
||||
import com.fabledsword.minstrel.theme.Section
|
||||
import com.fabledsword.minstrel.theme.SwitchRow
|
||||
|
||||
@Composable
|
||||
fun PasswordCard(viewModel: PasswordViewModel = hiltViewModel()) {
|
||||
@@ -41,6 +42,12 @@ fun PasswordCard(viewModel: PasswordViewModel = hiltViewModel()) {
|
||||
label = "Confirm new password",
|
||||
onChange = viewModel::setConfirm,
|
||||
)
|
||||
SwitchRow(
|
||||
title = "Sign out Subsonic apps too",
|
||||
summary = "Your API token and Subsonic password stop working.",
|
||||
checked = state.signOutSubsonic,
|
||||
onCheckedChange = viewModel::setSignOutSubsonic,
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Button(
|
||||
onClick = viewModel::change,
|
||||
|
||||
+11
-2
@@ -16,6 +16,7 @@ data class PasswordUiState(
|
||||
val current: String = "",
|
||||
val next: String = "",
|
||||
val confirm: String = "",
|
||||
val signOutSubsonic: Boolean = false,
|
||||
val isChanging: Boolean = false,
|
||||
val message: String? = null,
|
||||
)
|
||||
@@ -37,6 +38,8 @@ class PasswordViewModel @Inject constructor(
|
||||
fun setCurrent(value: String) = internal.update { it.copy(current = value, message = null) }
|
||||
fun setNext(value: String) = internal.update { it.copy(next = value, message = null) }
|
||||
fun setConfirm(value: String) = internal.update { it.copy(confirm = value, message = null) }
|
||||
fun setSignOutSubsonic(value: Boolean) =
|
||||
internal.update { it.copy(signOutSubsonic = value, message = null) }
|
||||
|
||||
fun change() {
|
||||
val s = internal.value
|
||||
@@ -55,9 +58,15 @@ class PasswordViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
internal.update { it.copy(isChanging = true, message = null) }
|
||||
try {
|
||||
repository.changePassword(current = s.current, next = s.next)
|
||||
repository.changePassword(
|
||||
current = s.current,
|
||||
next = s.next,
|
||||
signOutSubsonic = s.signOutSubsonic,
|
||||
)
|
||||
val signedOut =
|
||||
if (s.signOutSubsonic) "Your other devices and Subsonic apps" else "Your other devices"
|
||||
internal.update {
|
||||
PasswordUiState(message = "Password changed. Your other devices have been signed out.")
|
||||
PasswordUiState(message = "Password changed. $signedOut have been signed out.")
|
||||
}
|
||||
} catch (
|
||||
@Suppress("TooGenericExceptionCaught") e: Throwable,
|
||||
|
||||
Reference in New Issue
Block a user