Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
singe committed May 31, 2024
1 parent 14cf3d9 commit 2d1c362
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "tidcli",
platforms: [
.macOS(.v10_15)
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "tidcli"),
]
)
28 changes: 28 additions & 0 deletions Sources/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Foundation
import LocalAuthentication

let arguments = CommandLine.arguments
var promptMessage = "authenticate to proceed"
if arguments.count > 1 {
promptMessage = arguments[1]
}

let context = LAContext()
var error: NSError?

if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: promptMessage) { success, evaluationError in
if success {
print("Authentication was successful.")
} else {
print("Authentication failed.")
}
exit(success ? 0 : 1)
}
} else {
print("Touch ID is not available.")
exit(1)
}

// Keep the run loop running to wait for the async authentication callback.
RunLoop.main.run()
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Outrageously simple touch ID command line prompter

TouchID CLI (tidcli) simply pops a TouchID prompt.
It returns an exit code of 0 on success and 1 on failure.

You can use this to embed additional authentication steps into your shell script or the like.

Custom prompt information can be passed as the first argument.

# Building

Build a release binary with swift by running:

`swift build -c release`

The resulting binary will be in the `.build/release` directory as `tidcli`.

0 comments on commit 2d1c362

Please sign in to comment.