Created
January 29, 2016 17:53
-
-
Save BenjyWiener/d44b83d80f2f77e4f832 to your computer and use it in GitHub Desktop.
LocalAuthentication for Pyhtonista
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
commented
Feb 11, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment