Skip to content

Instantly share code, notes, and snippets.

@BenjyWiener
Created January 29, 2016 17:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BenjyWiener/d44b83d80f2f77e4f832 to your computer and use it in GitHub Desktop.
Save BenjyWiener/d44b83d80f2f77e4f832 to your computer and use it in GitHub Desktop.
LocalAuthentication for Pyhtonista
# coding: utf-8
from objc_util import *
import time
def authenticate(reason = ' '):
ObjCClass('NSBundle').bundleWithPath_('/System/Library/Frameworks/LocalAuthentication.framework').load()
context = ObjCClass('LAContext').alloc().init()
global result
result = None
retain_global(result)
def auth_response_handler(_cmd, success, _error):
global result
if success:
result = True
else:
error = ObjCInstance(_error)
if error.code() == -2:
result = False
auth_response_handler_block = ObjCBlock(auth_response_handler, None, [c_void_p, c_void_p, c_void_p])
reason = str(reason)
if reason == '':
reason = ' '
context.evaluatePolicy_localizedReason_reply_(2, reason, auth_response_handler_block)
while result == None:
pass
return result
@cclauss
Copy link

cclauss commented Feb 11, 2016

    reason = str(reason)
    if reason == '':
        reason = ' '

# could be shortened to:

    reason = str(reason) or ' '

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment