Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple program to interact with authd via the macOS authorization API Raw
import Foundation
let rightname = "sys.openfile.readonly./tmp/cantread.txt"
var status: OSStatus
var authref: AuthorizationRef?
let flags = AuthorizationFlags([.interactionAllowed, .extendRights, .preAuthorize])
status = AuthorizationCreate(nil, nil, flags, &authref)
assert(status == errAuthorizationSuccess)
var item = AuthorizationItem(name: rightname, valueLength: 0, value: nil, flags: 0)
var rights = AuthorizationRights(count: 1, items: &item)
status = AuthorizationCopyRights(authref!, &rights, nil, flags, nil)
assert(status == errAuthorizationSuccess)
var token = AuthorizationExternalForm()
status = AuthorizationMakeExternalForm(authref!, &token)
assert(status == errAuthorizationSuccess)
let data = NSData(bytes: &token.bytes, length: kAuthorizationExternalFormLength)
data.write(toFile: "./token", atomically: true)
print("External form written to ./token")
print("Press enter to quit")
let _ = readLine()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.