Skip to content

Commit

Permalink
Update swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Aug 13, 2024
1 parent 3a8129a commit 8bcd963
Showing 1 changed file with 71 additions and 63 deletions.
134 changes: 71 additions & 63 deletions languages/swift/iOS/App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let PIN = "1234"
struct ContentView: View {
private var http: URLSession

@State private var client: Client
@State private var client: Client? = nil

@State private var accessToken: String = ""

Expand All @@ -37,81 +37,89 @@ struct ContentView: View {
http = URLSession(
configuration: URLSessionConfiguration.default, delegate: IgnoreHttpsDelegate(),
delegateQueue: nil)

client = Client(settings: nil)
}

@State var setupBiometrics: Bool = true
@State var setupPin: Bool = true
@State var outputText: String = ""

var body: some View {
VStack {
Toggle("Setup biometric unlock after login", isOn: $setupBiometrics).padding(.init(top: 0, leading: 20, bottom: 0, trailing: 20))
Toggle("Setup PIN unlock after login", isOn: $setupPin).padding(.init(top: 0, leading: 20, bottom: 0, trailing: 20))

Button(action: {
Task {
do {
try await clientExamplePassword(clientAuth: client.auth(), clientCrypto: client.crypto(), setupBiometrics: setupBiometrics, setupPin: setupPin)
try await decryptVault(clientCrypto: client.crypto(), clientVault: client.vault())
} catch {
print("ERROR:", error)
switch client {
case .some(let client):
VStack {
Toggle("Setup biometric unlock after login", isOn: $setupBiometrics).padding(.init(top: 0, leading: 20, bottom: 0, trailing: 20))
Toggle("Setup PIN unlock after login", isOn: $setupPin).padding(.init(top: 0, leading: 20, bottom: 0, trailing: 20))

Button(action: {
Task {
do {
try await clientExamplePassword(clientAuth: client.auth(), clientCrypto: client.crypto(), setupBiometrics: setupBiometrics, setupPin: setupPin)
try await decryptVault(clientCrypto: client.crypto(), clientVault: client.vault())
} catch {
print("ERROR:", error)
}
}
}
}, label: {
Text("Login with username + password")
})

Divider().padding(30)

Button(action: {
Task {
do {
try await clientExampleBiometrics(clientCrypto: client.crypto())
try await decryptVault(clientCrypto: client.crypto(), clientVault: client.vault())
} catch {
print("ERROR:", error)
}, label: {
Text("Login with username + password")
})

Divider().padding(30)

Button(action: {
Task {
do {
try await clientExampleBiometrics(clientCrypto: client.crypto())
try await decryptVault(clientCrypto: client.crypto(), clientVault: client.vault())
} catch {
print("ERROR:", error)
}
}
}
}, label: {
Text("Unlock with biometrics")
})

Button(action: {
Task {
do {
try await clientExamplePin(clientCrypto: client.crypto())
try await decryptVault(clientCrypto: client.crypto(), clientVault: client.vault())
} catch {
print("ERROR:", error)
}, label: {
Text("Unlock with biometrics")
})

Button(action: {
Task {
do {
try await clientExamplePin(clientCrypto: client.crypto())
try await decryptVault(clientCrypto: client.crypto(), clientVault: client.vault())
} catch {
print("ERROR:", error)
}
}
}
}, label: {
Text("Unlock with PIN")
})

Button(action: {
Task {
do {
try await authenticatorTest(clientFido: client.platform().fido2())
} catch {
print("ERROR:", error)
}, label: {
Text("Unlock with PIN")
})

Button(action: {
Task {
do {
try await authenticatorTest(clientFido: client.platform().fido2())
} catch {
print("ERROR:", error)
}
}
}
}, label: {
Text("Passkey")
})
}, label: {
Text("Passkey")
})

Button(action: {
client = Client(settings: nil)
}, label: {
Text("Lock & reset client")
}).padding()

Text("Output: " + outputText).padding(.top)
Button(action: {
Task {
self.client = await Client.factory(settings: nil)
}
}, label: {
Text("Lock & reset client")
}).padding()

Text("Output: " + outputText).padding(.top)
}
.padding()
case nil:
VStack {}.task {
client = await Client.factory(settings: nil)
}
}
.padding()

}

func clientExamplePassword(clientAuth: ClientAuthProtocol, clientCrypto: ClientCryptoProtocol, setupBiometrics: Bool, setupPin: Bool) async throws {
Expand Down

0 comments on commit 8bcd963

Please sign in to comment.