[Web] Add u2f api from bitwardens repository to skip u2f when it is browser-provided
This commit is contained in:
parent
e695ae382c
commit
e3f73f26f1
|
@ -4,17 +4,41 @@
|
||||||
//license that can be found in the LICENSE file or at
|
//license that can be found in the LICENSE file or at
|
||||||
//https://developers.google.com/open-source/licenses/bsd
|
//https://developers.google.com/open-source/licenses/bsd
|
||||||
|
|
||||||
|
// ref: https://github.com/google/u2f-ref-code/blob/master/u2f-gae-demo/war/js/u2f-api.js
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview The U2F api.
|
* @fileoverview The U2F api.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modification:
|
||||||
|
* Wrap implementation so that we can exit if window.u2f is already supplied by the browser (see below).
|
||||||
|
*/
|
||||||
|
(function (root) {
|
||||||
|
/**
|
||||||
|
* Modification:
|
||||||
|
* Only continue load this library if window.u2f is not already supplied by the browser.
|
||||||
|
*/
|
||||||
|
var isFirefox = navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Gecko/') !== -1;
|
||||||
|
var browserImplementsU2f = !!((typeof root.u2f !== 'undefined') && root.u2f.register);
|
||||||
|
|
||||||
|
if (isFirefox && browserImplementsU2f) {
|
||||||
|
root.u2f.isSupported = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Namespace for the U2F api.
|
* Namespace for the U2F api.
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
var u2f = u2f || {};
|
var u2f = root.u2f || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modification:
|
||||||
|
* Check if browser supports U2F API before this wrapper was added.
|
||||||
|
*/
|
||||||
|
u2f.isSupported = !!(((typeof u2f !== 'undefined') && u2f.register) || ((typeof chrome !== 'undefined') && chrome.runtime));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIDO U2F Javascript API Version
|
* FIDO U2F Javascript API Version
|
||||||
|
@ -746,3 +770,10 @@ u2f.getApiVersion = function(callback, opt_timeoutSeconds) {
|
||||||
port.postMessage(req);
|
port.postMessage(req);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modification:
|
||||||
|
* Assign u2f back to window (root) scope.
|
||||||
|
*/
|
||||||
|
root.u2f = u2f;
|
||||||
|
}(this));
|
||||||
|
|
Loading…
Reference in New Issue