Add option to disable future login tokens

This commit is contained in:
Ilya Laktyushin 2024-04-17 21:19:06 +04:00
parent ff09220634
commit 8876026edb
4 changed files with 38 additions and 17 deletions

View File

@ -192,13 +192,15 @@ public final class AuthorizationSequenceController: NavigationController, ASAuth
return return
} }
controller?.inProgress = true controller?.inProgress = true
let disableAuthTokens = self.sharedContext.immediateExperimentalUISettings.disableReloginTokens
let authorizationPushConfiguration = self.sharedContext.authorizationPushConfiguration let authorizationPushConfiguration = self.sharedContext.authorizationPushConfiguration
|> take(1) |> take(1)
|> timeout(2.0, queue: .mainQueue(), alternate: .single(nil)) |> timeout(2.0, queue: .mainQueue(), alternate: .single(nil))
let _ = (authorizationPushConfiguration let _ = (authorizationPushConfiguration
|> deliverOnMainQueue).startStandalone(next: { [weak self] authorizationPushConfiguration in |> deliverOnMainQueue).startStandalone(next: { [weak self] authorizationPushConfiguration in
if let strongSelf = self { if let strongSelf = self {
strongSelf.actionDisposable.set((sendAuthorizationCode(accountManager: strongSelf.sharedContext.accountManager, account: strongSelf.account, phoneNumber: number, apiId: strongSelf.apiId, apiHash: strongSelf.apiHash, pushNotificationConfiguration: authorizationPushConfiguration, firebaseSecretStream: strongSelf.sharedContext.firebaseSecretStream, syncContacts: syncContacts, forcedPasswordSetupNotice: { value in strongSelf.actionDisposable.set((sendAuthorizationCode(accountManager: strongSelf.sharedContext.accountManager, account: strongSelf.account, phoneNumber: number, apiId: strongSelf.apiId, apiHash: strongSelf.apiHash, pushNotificationConfiguration: authorizationPushConfiguration, firebaseSecretStream: strongSelf.sharedContext.firebaseSecretStream, syncContacts: syncContacts, disableAuthTokens: disableAuthTokens, forcedPasswordSetupNotice: { value in
guard let entry = CodableEntry(ApplicationSpecificCounterNotice(value: value)) else { guard let entry = CodableEntry(ApplicationSpecificCounterNotice(value: value)) else {
return nil return nil
} }

View File

@ -101,6 +101,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
case storiesJpegExperiment(Bool) case storiesJpegExperiment(Bool)
case playlistPlayback(Bool) case playlistPlayback(Bool)
case enableQuickReactionSwitch(Bool) case enableQuickReactionSwitch(Bool)
case disableReloginTokens(Bool)
case voiceConference case voiceConference
case preferredVideoCodec(Int, String, String?, Bool) case preferredVideoCodec(Int, String, String?, Bool)
case disableVideoAspectScaling(Bool) case disableVideoAspectScaling(Bool)
@ -126,7 +127,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return DebugControllerSection.web.rawValue return DebugControllerSection.web.rawValue
case .keepChatNavigationStack, .skipReadHistory, .dustEffect, .crashOnSlowQueries, .crashOnMemoryPressure: case .keepChatNavigationStack, .skipReadHistory, .dustEffect, .crashOnSlowQueries, .crashOnMemoryPressure:
return DebugControllerSection.experiments.rawValue return DebugControllerSection.experiments.rawValue
case .clearTips, .resetNotifications, .crash, .fillLocalSavedMessageCache, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .resetTagHoles, .reindexUnread, .resetCacheIndex, .reindexCache, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .storiesExperiment, .storiesJpegExperiment, .playlistPlayback, .enableQuickReactionSwitch, .voiceConference, .experimentalCompatibility, .enableDebugDataDisplay, .acceleratedStickers, .browserExperiment, .localTranscription, .enableReactionOverrides, .restorePurchases: case .clearTips, .resetNotifications, .crash, .fillLocalSavedMessageCache, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .resetTagHoles, .reindexUnread, .resetCacheIndex, .reindexCache, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .storiesExperiment, .storiesJpegExperiment, .playlistPlayback, .enableQuickReactionSwitch, .voiceConference, .experimentalCompatibility, .enableDebugDataDisplay, .acceleratedStickers, .browserExperiment, .localTranscription, .enableReactionOverrides, .restorePurchases, .disableReloginTokens:
return DebugControllerSection.experiments.rawValue return DebugControllerSection.experiments.rawValue
case .logTranslationRecognition, .resetTranslationStates: case .logTranslationRecognition, .resetTranslationStates:
return DebugControllerSection.translation.rawValue return DebugControllerSection.translation.rawValue
@ -233,14 +234,16 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return 46 return 46
case .storiesJpegExperiment: case .storiesJpegExperiment:
return 47 return 47
case .playlistPlayback: case .disableReloginTokens:
return 48 return 48
case .enableQuickReactionSwitch: case .playlistPlayback:
return 49 return 49
case .voiceConference: case .enableQuickReactionSwitch:
return 50 return 50
case .voiceConference:
return 51
case let .preferredVideoCodec(index, _, _, _): case let .preferredVideoCodec(index, _, _, _):
return 51 + index return 52 + index
case .disableVideoAspectScaling: case .disableVideoAspectScaling:
return 100 return 100
case .enableNetworkFramework: case .enableNetworkFramework:
@ -1371,6 +1374,14 @@ private enum DebugControllerEntry: ItemListNodeEntry {
} }
}) })
}) })
case let .disableReloginTokens(value):
return ItemListSwitchItem(presentationData: presentationData, title: "Disable Relogin Tokens", value: value, sectionId: self.section, style: .blocks, updated: { value in
let _ = updateExperimentalUISettingsInteractively(accountManager: arguments.sharedContext.accountManager, { settings in
var settings = settings
settings.disableReloginTokens = value
return settings
}).start()
})
case let .hostInfo(_, string): case let .hostInfo(_, string):
return ItemListTextItem(presentationData: presentationData, text: .plain(string), sectionId: self.section) return ItemListTextItem(presentationData: presentationData, text: .plain(string), sectionId: self.section)
case .versionInfo: case .versionInfo:
@ -1453,6 +1464,7 @@ private func debugControllerEntries(sharedContext: SharedAccountContext, present
if case .internal = sharedContext.applicationBindings.appBuildType { if case .internal = sharedContext.applicationBindings.appBuildType {
entries.append(.storiesExperiment(experimentalSettings.storiesExperiment)) entries.append(.storiesExperiment(experimentalSettings.storiesExperiment))
entries.append(.storiesJpegExperiment(experimentalSettings.storiesJpegExperiment)) entries.append(.storiesJpegExperiment(experimentalSettings.storiesJpegExperiment))
entries.append(.disableReloginTokens(experimentalSettings.disableReloginTokens))
} }
entries.append(.playlistPlayback(experimentalSettings.playlistPlayback)) entries.append(.playlistPlayback(experimentalSettings.playlistPlayback))
entries.append(.enableQuickReactionSwitch(!experimentalSettings.disableQuickReaction)) entries.append(.enableQuickReactionSwitch(!experimentalSettings.disableQuickReaction))

View File

@ -142,7 +142,7 @@ private func sendFirebaseAuthorizationCode(accountManager: AccountManager<Telegr
} }
} }
public func sendAuthorizationCode(accountManager: AccountManager<TelegramAccountManagerTypes>, account: UnauthorizedAccount, phoneNumber: String, apiId: Int32, apiHash: String, pushNotificationConfiguration: AuthorizationCodePushNotificationConfiguration?, firebaseSecretStream: Signal<[String: String], NoError>, syncContacts: Bool, forcedPasswordSetupNotice: @escaping (Int32) -> (NoticeEntryKey, CodableEntry)?) -> Signal<SendAuthorizationCodeResult, AuthorizationCodeRequestError> { public func sendAuthorizationCode(accountManager: AccountManager<TelegramAccountManagerTypes>, account: UnauthorizedAccount, phoneNumber: String, apiId: Int32, apiHash: String, pushNotificationConfiguration: AuthorizationCodePushNotificationConfiguration?, firebaseSecretStream: Signal<[String: String], NoError>, syncContacts: Bool, disableAuthTokens: Bool = false, forcedPasswordSetupNotice: @escaping (Int32) -> (NoticeEntryKey, CodableEntry)?) -> Signal<SendAuthorizationCodeResult, AuthorizationCodeRequestError> {
var cloudValue: [Data] = [] var cloudValue: [Data] = []
if let list = NSUbiquitousKeyValueStore.default.object(forKey: "T_SLTokens") as? [String] { if let list = NSUbiquitousKeyValueStore.default.object(forKey: "T_SLTokens") as? [String] {
cloudValue = list.compactMap { string -> Data? in cloudValue = list.compactMap { string -> Data? in
@ -152,9 +152,6 @@ public func sendAuthorizationCode(accountManager: AccountManager<TelegramAccount
return Data(base64Encoded: stringData) return Data(base64Encoded: stringData)
} }
} }
#if DEBUG
cloudValue.removeAll()
#endif
return accountManager.transaction { transaction -> [Data] in return accountManager.transaction { transaction -> [Data] in
return transaction.getStoredLoginTokens() return transaction.getStoredLoginTokens()
} }
@ -162,16 +159,20 @@ public func sendAuthorizationCode(accountManager: AccountManager<TelegramAccount
|> mapToSignal { localAuthTokens -> Signal<SendAuthorizationCodeResult, AuthorizationCodeRequestError> in |> mapToSignal { localAuthTokens -> Signal<SendAuthorizationCodeResult, AuthorizationCodeRequestError> in
var authTokens = localAuthTokens var authTokens = localAuthTokens
#if DEBUG
authTokens.removeAll()
#endif
for data in cloudValue { for data in cloudValue {
if !authTokens.contains(data) { if !authTokens.contains(data) {
authTokens.insert(data, at: 0) authTokens.insert(data, at: 0)
} }
} }
if disableAuthTokens {
authTokens.removeAll()
}
#if DEBUG
authTokens.removeAll()
#endif
var flags: Int32 = 0 var flags: Int32 = 0
flags |= 1 << 5 //allowMissedCall flags |= 1 << 5 //allowMissedCall
flags |= 1 << 6 //tokens flags |= 1 << 6 //tokens

View File

@ -56,6 +56,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
public var dustEffect: Bool public var dustEffect: Bool
public var callV2: Bool public var callV2: Bool
public var allowWebViewInspection: Bool public var allowWebViewInspection: Bool
public var disableReloginTokens: Bool
public static var defaultSettings: ExperimentalUISettings { public static var defaultSettings: ExperimentalUISettings {
return ExperimentalUISettings( return ExperimentalUISettings(
@ -89,7 +90,8 @@ public struct ExperimentalUISettings: Codable, Equatable {
crashOnMemoryPressure: false, crashOnMemoryPressure: false,
dustEffect: false, dustEffect: false,
callV2: false, callV2: false,
allowWebViewInspection: false allowWebViewInspection: false,
disableReloginTokens: false
) )
} }
@ -124,7 +126,8 @@ public struct ExperimentalUISettings: Codable, Equatable {
crashOnMemoryPressure: Bool, crashOnMemoryPressure: Bool,
dustEffect: Bool, dustEffect: Bool,
callV2: Bool, callV2: Bool,
allowWebViewInspection: Bool allowWebViewInspection: Bool,
disableReloginTokens: Bool
) { ) {
self.keepChatNavigationStack = keepChatNavigationStack self.keepChatNavigationStack = keepChatNavigationStack
self.skipReadHistory = skipReadHistory self.skipReadHistory = skipReadHistory
@ -157,6 +160,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
self.dustEffect = dustEffect self.dustEffect = dustEffect
self.callV2 = callV2 self.callV2 = callV2
self.allowWebViewInspection = allowWebViewInspection self.allowWebViewInspection = allowWebViewInspection
self.disableReloginTokens = disableReloginTokens
} }
public init(from decoder: Decoder) throws { public init(from decoder: Decoder) throws {
@ -193,6 +197,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
self.dustEffect = try container.decodeIfPresent(Bool.self, forKey: "dustEffect") ?? false self.dustEffect = try container.decodeIfPresent(Bool.self, forKey: "dustEffect") ?? false
self.callV2 = try container.decodeIfPresent(Bool.self, forKey: "callV2") ?? false self.callV2 = try container.decodeIfPresent(Bool.self, forKey: "callV2") ?? false
self.allowWebViewInspection = try container.decodeIfPresent(Bool.self, forKey: "allowWebViewInspection") ?? false self.allowWebViewInspection = try container.decodeIfPresent(Bool.self, forKey: "allowWebViewInspection") ?? false
self.disableReloginTokens = try container.decodeIfPresent(Bool.self, forKey: "disableReloginTokens") ?? false
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -229,6 +234,7 @@ public struct ExperimentalUISettings: Codable, Equatable {
try container.encode(self.dustEffect, forKey: "dustEffect") try container.encode(self.dustEffect, forKey: "dustEffect")
try container.encode(self.callV2, forKey: "callV2") try container.encode(self.callV2, forKey: "callV2")
try container.encode(self.allowWebViewInspection, forKey: "allowWebViewInspection") try container.encode(self.allowWebViewInspection, forKey: "allowWebViewInspection")
try container.encode(self.disableReloginTokens, forKey: "disableReloginTokens")
} }
} }