Skip to content

Commit 2d1c362

Browse files
committed
First commit
1 parent 14cf3d9 commit 2d1c362

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

Package.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
)

Sources/main.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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()

readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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`.

0 commit comments

Comments
 (0)