Modern Apps git

← xtool.git

Login persistence

Commit
6e561d0d94c841930f426fa35bb0c27f02edd2a1
Author
Kabir Oberai <[email protected]>
When
2024-11-22 10:47 UTC (2 years ago)
Parents
5316905

Diff

Sources/SupersignCLISupport/AuthToken.swift
diff --git a/Sources/SupersignCLISupport/AuthToken.swift b/Sources/SupersignCLISupport/AuthToken.swiftindex 852d52b..ebd2af8 100644--- a/Sources/SupersignCLISupport/AuthToken.swift+++ b/Sources/SupersignCLISupport/AuthToken.swift@@ -57,4 +57,16 @@ extension AuthToken {         return "@\(data.base64EncodedString())"     } +    static func saved() throws -> Self {+        guard let string = try SupersignCLI.config.storage.string(forKey: "SUPAuthToken"),+              let token = AuthToken(string: string) else {+            throw Console.Error("Please log in with `supersign ds login` before running this command.")+        }+        return token+    }++    func save() throws {+        try SupersignCLI.config.storage.setString(string, forKey: "SUPAuthToken")+    }+ }
Sources/SupersignCLISupport/DSCommand.swift
diff --git a/Sources/SupersignCLISupport/DSCommand.swift b/Sources/SupersignCLISupport/DSCommand.swiftindex 62645da..45aae17 100644--- a/Sources/SupersignCLISupport/DSCommand.swift+++ b/Sources/SupersignCLISupport/DSCommand.swift@@ -65,6 +65,10 @@ struct DSLoginCommand: AsyncParsableCommand {     @Flag(name: [.short, .long]) var resetProvisioning = false     @Option(name: [.short, .long], help: "Apple ID") var username: String?     @Option(name: [.short, .long]) var password: String?+    @Flag(+        name: [.long],+        help: "Print the auth token to standard output instead of persisting it."+    ) var printToken = false      func run() async throws {         let fullToken = try await AuthToken.retrieve(@@ -73,10 +77,15 @@ struct DSLoginCommand: AsyncParsableCommand {             password: self.password,             resetProvisioning: resetProvisioning         )-        guard let string = fullToken.string else {-            throw Console.Error("Could not encode token.")+        if printToken {+            guard let string = fullToken.string else {+                throw Console.Error("Could not encode token.")+            }+            print(string)+        } else {+            try fullToken.save()+            print("Logged in!")         }-        print(string)     } } @@ -89,13 +98,14 @@ struct DSTeamsListCommand: AsyncParsableCommand {     @Option(name: .shortAndLong) var account: String?      func run() async throws {+        let token = try account.flatMap(AuthToken.init(string:)) ?? AuthToken.saved()+         let deviceInfo = try DeviceInfo.fetch() //        let anisetteProvider = SupersetteDataProvider(deviceInfo: deviceInfo)         let anisetteProvider = try ADIDataProvider.omnisetteProvider(             deviceInfo: deviceInfo, storage: SupersignCLI.config.storage         ) -        let token = try await AuthToken.retrieve(deviceInfo: deviceInfo, account: account)         let client = DeveloperServicesClient(             loginToken: token.dsToken,             deviceInfo: deviceInfo,
Sources/SupersignCLISupport/InstallCommand.swift
diff --git a/Sources/SupersignCLISupport/InstallCommand.swift b/Sources/SupersignCLISupport/InstallCommand.swiftindex ed0ae63..2def7cd 100644--- a/Sources/SupersignCLISupport/InstallCommand.swift+++ b/Sources/SupersignCLISupport/InstallCommand.swift@@ -21,19 +21,10 @@ struct InstallCommand: ParsableCommand {     ) var path: String      func run() throws {-        let username: String-        let credentials: IntegratedInstaller.Credentials+        let token = try account.flatMap(AuthToken.init(string:)) ?? AuthToken.saved() -        if let account = account, let auth = AuthToken(string: account) {-            username = auth.appleID-            credentials = .token(auth.dsToken)-        } else {-            guard let appleID = account ?? Console.prompt("Apple ID: "),-                  let password = Console.getPassword("Password: ")-            else { return }-            username = appleID-            credentials = .password(password)-        }+        let username = token.appleID+        let credentials: IntegratedInstaller.Credentials = .token(token.dsToken)          print("Installing to device: \(client.deviceName) (udid: \(client.udid))")