mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-25 20:15:34 +02:00
Add version to ServerConnectionConfig on iOS
This commit is contained in:
parent
52f86cbce9
commit
5804c54656
7 changed files with 37 additions and 8 deletions
|
@ -22,6 +22,9 @@
|
|||
<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>
|
||||
</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 class="my-1 py-4 w-full">
|
||||
<ui-btn class="w-full" @click="newServerConfigClick">{{ $strings.ButtonAddNewServer }}</ui-btn>
|
||||
|
@ -829,7 +832,7 @@ export default {
|
|||
this.serverConfig.refreshToken = user.refreshToken
|
||||
} else {
|
||||
// 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()
|
||||
return
|
||||
}
|
||||
|
@ -907,6 +910,7 @@ export default {
|
|||
setForceReloginForNewAuth() {
|
||||
this.error = this.$strings.MessageOldServerAuthReLoginRequired
|
||||
this.showAuth = true
|
||||
this.showForm = true
|
||||
},
|
||||
init() {
|
||||
// Handle force re-login for servers using new JWT auth but still using an old token in the server config
|
||||
|
|
|
@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
// Override point for customization after application launch.
|
||||
|
||||
let configuration = Realm.Configuration(
|
||||
schemaVersion: 19,
|
||||
schemaVersion: 20,
|
||||
migrationBlock: { [weak self] migration, oldSchemaVersion in
|
||||
if (oldSchemaVersion < 1) {
|
||||
self?.logger.log("Realm schema version was \(oldSchemaVersion)")
|
||||
|
@ -67,7 +67,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
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
|
||||
|
|
|
@ -53,12 +53,18 @@ public class AbsDatabase: CAPPlugin, CAPBridgedPlugin {
|
|||
@objc func setCurrentServerConnectionConfig(_ call: CAPPluginCall) {
|
||||
var id = call.getString("id")
|
||||
let address = call.getString("address", "")
|
||||
let version = call.getString("version", "")
|
||||
let userId = call.getString("userId", "")
|
||||
let username = call.getString("username", "")
|
||||
let token = call.getString("token", "")
|
||||
let refreshToken = call.getString("refreshToken", "") // Refresh only sent after login or refresh
|
||||
|
||||
let name = "\(address) (\(username))"
|
||||
|
||||
if (refreshToken != "") {
|
||||
// TODO: Implement secure storage
|
||||
}
|
||||
|
||||
if id == nil {
|
||||
id = "\(address)@\(username)".toBase64()
|
||||
}
|
||||
|
@ -68,6 +74,7 @@ public class AbsDatabase: CAPPlugin, CAPBridgedPlugin {
|
|||
config.index = 0
|
||||
config.name = name
|
||||
config.address = address
|
||||
config.version = version
|
||||
config.userId = userId
|
||||
config.username = username
|
||||
config.token = token
|
||||
|
@ -82,6 +89,16 @@ public class AbsDatabase: CAPPlugin, CAPBridgedPlugin {
|
|||
|
||||
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) {
|
||||
Store.serverConfig = nil
|
||||
call.resolve()
|
||||
|
|
|
@ -13,6 +13,7 @@ class ServerConnectionConfig: Object {
|
|||
@Persisted(indexed: true) var index: Int = 1
|
||||
@Persisted var name: String = ""
|
||||
@Persisted var address: String = ""
|
||||
@Persisted var version: String = ""
|
||||
@Persisted var userId: String = ""
|
||||
@Persisted var username: String = ""
|
||||
@Persisted var token: String = ""
|
||||
|
@ -29,6 +30,7 @@ func convertServerConnectionConfigToJSON(config: ServerConnectionConfig) -> Dict
|
|||
"name": config.name,
|
||||
"index": config.index,
|
||||
"address": config.address,
|
||||
"version": config.version,
|
||||
"userId": config.userId,
|
||||
"username": config.username,
|
||||
"token": config.token,
|
||||
|
|
|
@ -27,6 +27,7 @@ class Database {
|
|||
try existing.update {
|
||||
existing.name = config.name
|
||||
existing.address = config.address
|
||||
existing.version = config.version
|
||||
existing.userId = config.userId
|
||||
existing.username = config.username
|
||||
existing.token = config.token
|
||||
|
|
|
@ -154,9 +154,9 @@ export default {
|
|||
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
|
||||
// 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
|
||||
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
|
||||
await this.$store.dispatch('user/logout')
|
||||
this.$router.push(`/connect?error=oldAuthToken&serverConnectionConfigId=${serverConfig.id}`)
|
||||
|
|
|
@ -325,7 +325,7 @@
|
|||
"MessageNoSeries": "No series",
|
||||
"MessageNoUpdatesWereNecessary": "No updates were necessary",
|
||||
"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",
|
||||
"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.",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue