1
0
mirror of https://github.com/bitwarden/web synced 2025-12-06 00:03:28 +00:00
Files
web/connectors/webauthn.23cf804cd44e7c534791.js
github-actions[bot] 44a0a3183d Deploy 2.27.0 (#1546)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-03-15 19:49:18 -06:00

2 lines
3.9 KiB
JavaScript

(()=>{"use strict";var e={32728:(e,t)=>{function n(e){if(Array.isArray(e)&&(e=Uint8Array.from(e)),e instanceof ArrayBuffer&&(e=new Uint8Array(e)),e instanceof Uint8Array){let t="";const n=e.byteLength;for(let r=0;r<n;r++)t+=String.fromCharCode(e[r]);e=window.btoa(t)}if("string"!=typeof e)throw new Error("could not coerce to string");return e=e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=*$/g,"")}Object.defineProperty(t,"__esModule",{value:!0}),t.parseWebauthnJson=t.buildDataString=void 0,t.buildDataString=function(e){const t=e.response,r=new Uint8Array(t.authenticatorData),a=new Uint8Array(t.clientDataJSON),o=new Uint8Array(e.rawId),i=new Uint8Array(t.signature),c={id:e.id,rawId:n(o),type:e.type,extensions:e.getClientExtensionResults(),response:{authenticatorData:n(r),clientDataJson:n(a),signature:n(i)}};return JSON.stringify(c)},t.parseWebauthnJson=function(e){const t=JSON.parse(e),n=t.challenge.replace(/-/g,"+").replace(/_/g,"/");return t.challenge=Uint8Array.from(atob(n),(e=>e.charCodeAt(0))),t.allowCredentials.forEach((e=>{const t=e.id.replace(/\_/g,"/").replace(/\-/g,"+");e.id=Uint8Array.from(atob(t),(e=>e.charCodeAt(0)))})),t}},53204:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.b64Decode=t.getQsParam=void 0,t.getQsParam=function(e){const t=window.location.href;e=e.replace(/[\[\]]/g,"\\$&");const n=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(t);return n?n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):"":null},t.b64Decode=function(e,t=!1){return t&&(e=e.replace(/ /g,"+")),decodeURIComponent(Array.prototype.map.call(atob(e),(e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2))).join(""))}},48672:(e,t,n)=>{n.r(t)}},t={};function n(r){var a=t[r];if(void 0!==a)return a.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};(()=>{const e=n(53204),t=n(32728);n(48672);const r="bitwarden://webauthn-callback";let a,o=!1,i=null,c=null,d=null,s=null,l=null,u=!1,p=!1,g=!1,f=null;function b(){if(o)return;if(s=e.getQsParam("parent"),!s)return void h("No parent.");s=decodeURIComponent(s),l=new URL(s).origin;"1"===e.getQsParam("v")?function(){const t=e.getQsParam("data");if(!t)return void h("No data.");a=e.b64Decode(t),i=e.getQsParam("headerText"),c=e.getQsParam("btnText"),d=e.getQsParam("btnReturnText")}():function(){let t=null;try{t=JSON.parse(e.b64Decode(e.getQsParam("data")))}catch(n){return void h("Cannot parse data.")}u=null!=t.callbackUri||!0===t.mobile,a=t.data,i=t.headerText,c=t.btnText,d=t.btnReturnText}(),o=!0}function m(){if(g=!1,"credentials"in navigator)if(b(),a){try{f=t.parseWebauthnJson(a)}catch(e){return void h("Cannot parse webauthn data.")}p=!1,u||-1!==navigator.userAgent.indexOf(" Safari/")&&-1===navigator.userAgent.indexOf("Chrome")||y()}else h("No data.");else h("WebAuthn is not supported in this browser.")}function y(){p||navigator.credentials.get({publicKey:f}).then(w).catch(h)}function h(e){u?(document.location.replace(r+"?error="+encodeURIComponent(e)),v(r+"?error="+encodeURIComponent(e))):parent.postMessage("error|"+e,s)}function w(e){if(g)return;const n=t.buildDataString(e);u?(document.location.replace(r+"?data="+encodeURIComponent(n)),v(r+"?data="+encodeURIComponent(n))):(parent.postMessage("success|"+n,s),g=!0)}function v(e){const t=document.getElementById("webauthn-button");t.innerText=decodeURI(d),t.onclick=()=>{document.location.replace(e)}}document.addEventListener("DOMContentLoaded",(()=>{var e;if(m(),window.addEventListener("message",(e=>{e.origin&&""!==e.origin&&e.origin===l&&("stop"===e.data?p=!0:"start"===e.data&&p&&m())}),!1),e="ready",u||parent.postMessage("info|"+e,s),b(),i){document.getElementById("webauthn-header").innerText=decodeURI(i)}if(c){const e=document.getElementById("webauthn-button");e.innerText=decodeURI(c),e.onclick=y}}))})()})();
//# sourceMappingURL=webauthn.23cf804cd44e7c534791.js.map