Add version to ServerConnectionConfig on iOS

This commit is contained in:
advplyr 2025-07-05 14:28:02 -05:00
parent 52f86cbce9
commit 5804c54656
7 changed files with 37 additions and 8 deletions

View file

@ -22,6 +22,9 @@
<p class="text-xs text-warning">{{ $strings.MessageOldServerAuthWarning }}</p> <p class="text-xs text-warning">{{ $strings.MessageOldServerAuthWarning }}</p>
<ui-btn class="text-xs whitespace-nowrap" :padding-x="2" :padding-y="1" @click="showOldAuthWarningDialog">{{ $strings.LabelMoreInfo }}</ui-btn> <ui-btn class="text-xs whitespace-nowrap" :padding-x="2" :padding-y="1" @click="showOldAuthWarningDialog">{{ $strings.LabelMoreInfo }}</ui-btn>
</div> </div>
<div v-else-if="!config.version" class="flex flex-nowrap justify-between items-center space-x-4 pt-4">
<p class="text-xs text-warning">No server version set. Connect to update server config.</p>
</div>
</div> </div>
<div class="my-1 py-4 w-full"> <div class="my-1 py-4 w-full">
<ui-btn class="w-full" @click="newServerConfigClick">{{ $strings.ButtonAddNewServer }}</ui-btn> <ui-btn class="w-full" @click="newServerConfigClick">{{ $strings.ButtonAddNewServer }}</ui-btn>
@ -829,7 +832,7 @@ export default {
this.serverConfig.refreshToken = user.refreshToken this.serverConfig.refreshToken = user.refreshToken
} else { } else {
// Detect if the connection config is using the old token. If so, force re-login // Detect if the connection config is using the old token. If so, force re-login
if (this.serverConfig.token === user.token) { if (this.serverConfig.token === user.token || user.isOldToken) {
this.setForceReloginForNewAuth() this.setForceReloginForNewAuth()
return return
} }
@ -907,6 +910,7 @@ export default {
setForceReloginForNewAuth() { setForceReloginForNewAuth() {
this.error = this.$strings.MessageOldServerAuthReLoginRequired this.error = this.$strings.MessageOldServerAuthReLoginRequired
this.showAuth = true this.showAuth = true
this.showForm = true
}, },
init() { init() {
// Handle force re-login for servers using new JWT auth but still using an old token in the server config // Handle force re-login for servers using new JWT auth but still using an old token in the server config

View file

@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Override point for customization after application launch. // Override point for customization after application launch.
let configuration = Realm.Configuration( let configuration = Realm.Configuration(
schemaVersion: 19, schemaVersion: 20,
migrationBlock: { [weak self] migration, oldSchemaVersion in migrationBlock: { [weak self] migration, oldSchemaVersion in
if (oldSchemaVersion < 1) { if (oldSchemaVersion < 1) {
self?.logger.log("Realm schema version was \(oldSchemaVersion)") self?.logger.log("Realm schema version was \(oldSchemaVersion)")
@ -67,7 +67,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
newObject?["disableSleepTimerFadeOut"] = false newObject?["disableSleepTimerFadeOut"] = false
} }
} }
if (oldSchemaVersion < 20) {
self?.logger.log("Realm schema version was \(oldSchemaVersion)... Adding version to ServerConnectionConfigs")
migration.enumerateObjects(ofType: ServerConnectionConfig.className()) { oldObject, newObject in
newObject?["version"] = ""
}
}
} }
) )
Realm.Configuration.defaultConfiguration = configuration Realm.Configuration.defaultConfiguration = configuration

View file

@ -53,12 +53,18 @@ public class AbsDatabase: CAPPlugin, CAPBridgedPlugin {
@objc func setCurrentServerConnectionConfig(_ call: CAPPluginCall) { @objc func setCurrentServerConnectionConfig(_ call: CAPPluginCall) {
var id = call.getString("id") var id = call.getString("id")
let address = call.getString("address", "") let address = call.getString("address", "")
let version = call.getString("version", "")
let userId = call.getString("userId", "") let userId = call.getString("userId", "")
let username = call.getString("username", "") let username = call.getString("username", "")
let token = call.getString("token", "") let token = call.getString("token", "")
let refreshToken = call.getString("refreshToken", "") // Refresh only sent after login or refresh
let name = "\(address) (\(username))" let name = "\(address) (\(username))"
if (refreshToken != "") {
// TODO: Implement secure storage
}
if id == nil { if id == nil {
id = "\(address)@\(username)".toBase64() id = "\(address)@\(username)".toBase64()
} }
@ -68,6 +74,7 @@ public class AbsDatabase: CAPPlugin, CAPBridgedPlugin {
config.index = 0 config.index = 0
config.name = name config.name = name
config.address = address config.address = address
config.version = version
config.userId = userId config.userId = userId
config.username = username config.username = username
config.token = token config.token = token
@ -82,6 +89,16 @@ public class AbsDatabase: CAPPlugin, CAPBridgedPlugin {
call.resolve() call.resolve()
} }
@objc func getRefreshToken(_ call: CAPPluginCall) {
let serverConnectionConfigId = call.getString("serverConnectionConfigId", "")
// TODO: Implement secure storage
call.resolve()
}
@objc func clearRefreshToken(_ call: CAPPluginCall) {
let serverConnectionConfigId = call.getString("serverConnectionConfigId", "")
// TODO: Implement secure storage
call.resolve()
}
@objc func logout(_ call: CAPPluginCall) { @objc func logout(_ call: CAPPluginCall) {
Store.serverConfig = nil Store.serverConfig = nil
call.resolve() call.resolve()

View file

@ -13,6 +13,7 @@ class ServerConnectionConfig: Object {
@Persisted(indexed: true) var index: Int = 1 @Persisted(indexed: true) var index: Int = 1
@Persisted var name: String = "" @Persisted var name: String = ""
@Persisted var address: String = "" @Persisted var address: String = ""
@Persisted var version: String = ""
@Persisted var userId: String = "" @Persisted var userId: String = ""
@Persisted var username: String = "" @Persisted var username: String = ""
@Persisted var token: String = "" @Persisted var token: String = ""
@ -29,6 +30,7 @@ func convertServerConnectionConfigToJSON(config: ServerConnectionConfig) -> Dict
"name": config.name, "name": config.name,
"index": config.index, "index": config.index,
"address": config.address, "address": config.address,
"version": config.version,
"userId": config.userId, "userId": config.userId,
"username": config.username, "username": config.username,
"token": config.token, "token": config.token,

View file

@ -27,6 +27,7 @@ class Database {
try existing.update { try existing.update {
existing.name = config.name existing.name = config.name
existing.address = config.address existing.address = config.address
existing.version = config.version
existing.userId = config.userId existing.userId = config.userId
existing.username = config.username existing.username = config.username
existing.token = config.token existing.token = config.token

View file

@ -154,9 +154,9 @@ export default {
if (this.$isValidVersion(serverSettings.version, '2.26.0')) { if (this.$isValidVersion(serverSettings.version, '2.26.0')) {
// Check if the server is using the new JWT auth and is still using an old token in the server config // Check if the server is using the new JWT auth and is still using an old token in the server config
// If so, redirect to /connect and request to re-login // If so, redirect to /connect and request to re-login
if (serverConfig.token === user.token) { if (serverConfig.token === user.token || user.isOldToken) {
this.attemptingConnection = false this.attemptingConnection = false
AbsLogger.info({ tag: 'default', message: `attemptConnection: Server is using new JWT auth but is still using an old token (server version: ${serverSettings.version}) (${serverConfig.name})` }) AbsLogger.info({ tag: 'default', message: `attemptConnection: Server is using new JWT auth but config is still using an old token (server version: ${serverSettings.version}) (${serverConfig.name})` })
// Clear last server config // Clear last server config
await this.$store.dispatch('user/logout') await this.$store.dispatch('user/logout')
this.$router.push(`/connect?error=oldAuthToken&serverConnectionConfigId=${serverConfig.id}`) this.$router.push(`/connect?error=oldAuthToken&serverConnectionConfigId=${serverConfig.id}`)

View file

@ -325,7 +325,7 @@
"MessageNoSeries": "No series", "MessageNoSeries": "No series",
"MessageNoUpdatesWereNecessary": "No updates were necessary", "MessageNoUpdatesWereNecessary": "No updates were necessary",
"MessageNoUserPlaylists": "You have no playlists", "MessageNoUserPlaylists": "You have no playlists",
"MessageOldServerAuthReLoginRequired": "A new authentication system was added in server v2.26.0. Re-login is required for this server connection.", "MessageOldServerAuthReLoginRequired": "A new authentication system was added in server v2.26.0. Please re-login to use the more secure authentication.",
"MessageOldServerAuthWarning": "Server is using out-dated authentication", "MessageOldServerAuthWarning": "Server is using out-dated authentication",
"MessageOldServerAuthWarningHelp": "Authentication was updated in server v2.26.0 to use a more secure method. A future app update will require server version v2.26.0 or higher. You will need to re-login after updating the server.", "MessageOldServerAuthWarningHelp": "Authentication was updated in server v2.26.0 to use a more secure method. A future app update will require server version v2.26.0 or higher. You will need to re-login after updating the server.",
"MessageOldServerConnectionWarning": "Server connection config is using an old user ID. Please delete and re-add this server connection.", "MessageOldServerConnectionWarning": "Server connection config is using an old user ID. Please delete and re-add this server connection.",