app/lib/tiTouchIdHandler.js
// Start the authentication listener, tell it how to react to the user (via callbacks).
Start the authentication listener, tell it how to react to the user (via callbacks).
Start the authentication listener tell it how to react to the user ( via callbacks ) .
function start(config) {
		if (OS_IOS) {
			if (tiTouchId && config) {
				var defaultFailedAuthCB = (typeof config.failedAuthCB === 'function') ? config.failedAuthCB : function() {
					console.error('[tiTouchIdHandler] - Authorization failed, however no behavior was defined to handle it.');
				};
				var successAuthCB = (typeof config.successfulAuthCB === 'function') ? config.successfulAuthCB : function() {
					console.error('[tiTouchIdHandler] - A successful authorization occurred, however no handler was defined. Thus treating it as a failure.');
					defaultFailedAuthCB();
				};
				var callbacks = {
					successfulAuthCB : successAuthCB,
					failedAuthCB : config.failedAuthCB || defaultFailedAuthCB,
					userCancelCB : config.userCancelCB || defaultFailedAuthCB,
					userFallbackCB : config.userFallbackCB || defaultFailedAuthCB,
					notEnrolledCB : config.notEnrolledCB || defaultFailedAuthCB,
					notAvailableCB : config.notAvailableCB || defaultFailedAuthCB,
					systemCancelCB : config.systemCancelCB || defaultFailedAuthCB,
					passcodeNotSetCB : config.passcodeNotSetCB || defaultFailedAuthCB,
				};
				var reasonMessage = (typeof config.reasonMessage === 'string') ? config.reasonMessage : 'Fingerprint Authorization';
				if (isTouchIdAvailable()) {
					tiTouchId.authenticate({
						reason: reasonMessage,
						callback: function(e) {
							if (e.success) {
								callbacks.successfulAuthCB();
							} else {
								switch (e.code) {
									case tiTouchId.ERROR_USER_CANCEL: 
										callbacks.userCancelCB();
										break;
									case tiTouchId.ERROR_USER_FALLBACK: 
										callbacks.userFallbackCB();
										break;
									case tiTouchId.ERROR_TOUCH_ID_NOT_ENROLLED: 
										callbacks.notEnrolledCB();
										break;
									case tiTouchId.ERROR_TOUCH_ID_NOT_AVAILABLE: 
										callbacks.notAvailableCB();
										break;
									case tiTouchId.ERROR_SYSTEM_CANCEL: 
										callbacks.systemCancelCB();
										break;
									case tiTouchId.ERROR_PASSCODE_NOT_SET: 
										callbacks.passcodeNotSetCB();
										break;
									case tiTouchId.ERROR_AUTHENTICATION_FAILED: 
									default:
										callbacks.failedAuthCB();
										break;
								}
							}
						}
					});
				} else {
					console.error('[tiTouchIdHandler] - Device is not configured for Touch ID authentication.');
					callbacks.notAvailableCB();
				}
			} else {
				console.error('[tiTouchIdHandler] - Invalid input configuration, cannot start.');
			}
		} else {
			console.error('[tiTouchIdHandler] - Touch ID is not available for this OS.');
		}
	}
function start ( config ) { if ( OS_IOS ) { if ( tiTouchId && config ) { var defaultFailedAuthCB = ( typeof config . failedAuthCB === 'function' ) ? config . failedAuthCB : function ( ) { console . error ( '[tiTouchIdHandler] - Authorization failed, however no behavior was defined to handle it.' ) ; } ; var successAuthCB = ( typeof config . successfulAuthCB === 'function' ) ? config . successfulAuthCB : function ( ) { console . error ( '[tiTouchIdHandler] - A successful authorization occurred, however no handler was defined. Thus treating it as a failure.' ) ; defaultFailedAuthCB ( ) ; } ; var callbacks = { successfulAuthCB : successAuthCB , failedAuthCB : config . failedAuthCB || defaultFailedAuthCB , userCancelCB : config . userCancelCB || defaultFailedAuthCB , userFallbackCB : config . userFallbackCB || defaultFailedAuthCB , notEnrolledCB : config . notEnrolledCB || defaultFailedAuthCB , notAvailableCB : config . notAvailableCB || defaultFailedAuthCB , systemCancelCB : config . systemCancelCB || defaultFailedAuthCB , passcodeNotSetCB : config . passcodeNotSetCB || defaultFailedAuthCB , } ; var reasonMessage = ( typeof config . reasonMessage === 'string' ) ? config . reasonMessage : 'Fingerprint Authorization' ; if ( isTouchIdAvailable ( ) ) { tiTouchId . authenticate ( { reason : reasonMessage , callback : function ( e ) { if ( e . success ) { callbacks . successfulAuthCB ( ) ; } else { switch ( e . code ) { case tiTouchId . ERROR_USER_CANCEL : callbacks . userCancelCB ( ) ; break ; case tiTouchId . ERROR_USER_FALLBACK : callbacks . userFallbackCB ( ) ; break ; case tiTouchId . ERROR_TOUCH_ID_NOT_ENROLLED : callbacks . notEnrolledCB ( ) ; break ; case tiTouchId . ERROR_TOUCH_ID_NOT_AVAILABLE : callbacks . notAvailableCB ( ) ; break ; case tiTouchId . ERROR_SYSTEM_CANCEL : callbacks . systemCancelCB ( ) ; break ; case tiTouchId . ERROR_PASSCODE_NOT_SET : callbacks . passcodeNotSetCB ( ) ; break ; case tiTouchId . ERROR_AUTHENTICATION_FAILED : default : callbacks . failedAuthCB ( ) ; break ; } } } } ) ; } else { console . error ( '[tiTouchIdHandler] - Device is not configured for Touch ID authentication.' ) ; callbacks . notAvailableCB ( ) ; } } else { console . error ( '[tiTouchIdHandler] - Invalid input configuration, cannot start.' ) ; } } else { console . error ( '[tiTouchIdHandler] - Touch ID is not available for this OS.' ) ; } }
Start the authentication listener, tell it how to react to the user (via callbacks).
Start the authentication listener tell it how to react to the user ( via callbacks ) .
// Make sure we can receive events, and that we're configured. // Define default handlers in case some are not provided. // Fail the authorization so the app can deal with it. // Configure the callbacks, use the defaults if necessary. // Initiate the Touch ID authentication process. // Failed. // console.error('[tiTouchIdHandler] - authenticate() - e.error=' + e.error); // console.error('[tiTouchIdHandler] - authenticate() - e.code=' + e.code); // The user canceled authentication. // The user tapped the fallback button to enter their passcode. // Touch ID does not have any enrolled fingerprints. // Touch ID is not available on the device. // The OS (iOS) cancelled authentication. // The passcode is not set for the device. // Handle all other failures the same. // The authentication was not successful.