2 /** global: PMA_messages */
4 AJAX.registerOnload('u2f.js', function () {
5 var $inputReg = $('#u2f_registration_response');
6 if ($inputReg.length > 0) {
7 var $formReg = $inputReg.parents('form');
8 $formReg.find('input[type=submit]').hide();
9 setTimeout(function () {
10 // A magic JS function that talks to the USB device. This function will keep polling for the USB device until it finds one.
11 var request = JSON.parse($inputReg.attr('data-request'));
12 u2f.register(request.appId, [request], JSON.parse($inputReg.attr('data-signatures')), function (data) {
13 // Handle returning error data
14 if (data.errorCode && data.errorCode !== 0) {
15 if (data.errorCode === 5) {
16 PMA_ajaxShowMessage(PMA_messages.strU2FTimeout, false);
19 PMA_sprintf(PMA_messages.strU2FError, data.errorCode), false
25 // Fill and submit form.
26 $inputReg.val(JSON.stringify(data));
31 var $inputAuth = $('#u2f_authentication_response');
32 if ($inputAuth.length > 0) {
33 var $formAuth = $inputAuth.parents('form');
34 $formAuth.find('input[type=submit]').hide();
35 setTimeout(function () {
36 // Magic JavaScript talking to your HID
37 // appid, challenge, authenticateRequests
38 var request = JSON.parse($inputAuth.attr('data-request'));
39 var handles = [request[0].keyHandle];
40 u2f.sign(request[0].appId, request[0].challenge, request, function (data) {
41 // Handle returning error data
42 if (data.errorCode && data.errorCode !== 0) {
43 if (data.errorCode === 5) {
44 PMA_ajaxShowMessage(PMA_messages.strU2FTimeout, false);
47 PMA_sprintf(PMA_messages.strU2FError, data.errorCode), false
53 // Fill and submit form.
54 $inputAuth.val(JSON.stringify(data));