File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // swift-tools-version: 5.10
2+ // The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+ import PackageDescription
5+
6+ let package = Package (
7+ name: " tidcli " ,
8+ platforms: [
9+ . macOS( . v10_15)
10+ ] ,
11+ targets: [
12+ // Targets are the basic building blocks of a package, defining a module or a test suite.
13+ // Targets can depend on other targets in this package and products from dependencies.
14+ . executableTarget(
15+ name: " tidcli " ) ,
16+ ]
17+ )
Original file line number Diff line number Diff line change 1+ import Foundation
2+ import LocalAuthentication
3+
4+ let arguments = CommandLine . arguments
5+ var promptMessage = " authenticate to proceed "
6+ if arguments. count > 1 {
7+ promptMessage = arguments [ 1 ]
8+ }
9+
10+ let context = LAContext ( )
11+ var error : NSError ?
12+
13+ if context. canEvaluatePolicy ( . deviceOwnerAuthenticationWithBiometrics, error: & error) {
14+ context. evaluatePolicy ( . deviceOwnerAuthenticationWithBiometrics, localizedReason: promptMessage) { success, evaluationError in
15+ if success {
16+ print ( " Authentication was successful. " )
17+ } else {
18+ print ( " Authentication failed. " )
19+ }
20+ exit ( success ? 0 : 1 )
21+ }
22+ } else {
23+ print ( " Touch ID is not available. " )
24+ exit ( 1 )
25+ }
26+
27+ // Keep the run loop running to wait for the async authentication callback.
28+ RunLoop . main. run ( )
Original file line number Diff line number Diff line change 1+ # Outrageously simple touch ID command line prompter
2+
3+ TouchID CLI (tidcli) simply pops a TouchID prompt.
4+ It returns an exit code of 0 on success and 1 on failure.
5+
6+ You can use this to embed additional authentication steps into your shell script or the like.
7+
8+ Custom prompt information can be passed as the first argument.
9+
10+ # Building
11+
12+ Build a release binary with swift by running:
13+
14+ ` swift build -c release `
15+
16+ The resulting binary will be in the ` .build/release ` directory as ` tidcli ` .
You can’t perform that action at this time.
0 commit comments