diff --git a/examples/simple-demo/index.js b/examples/simple-demo/index.js index a0b2c5e..35533c1 100644 --- a/examples/simple-demo/index.js +++ b/examples/simple-demo/index.js @@ -19,7 +19,7 @@ async function enroll (event) { } async function authenticate (cui = false) { - const username = document.getElementById('username').value + const username = encodeURIComponent(document.getElementById('username').value) const authentication = new trusona.WebAuthnAuthentication() document.getElementById('credentials').replaceChildren([]) @@ -52,7 +52,7 @@ async function authenticate (cui = false) { async function jwtApi (username) { try { // *** DO NOT USE THIS JWT GENERATOR IN A PRODUCTION ENVIRONMENT *** - const response = await fetch(`https://jwks-delegate.lab.trusona.net/jwt?sub=${username}`) + const response = await fetch(`https://jwks-delegate.lab.trusona.net/jwt?sub=${encodeURIComponent(username)}`) const data = await response.json() return await Promise.resolve(data.jwt) } catch (e) { diff --git a/examples/simple-demo/trusona-webauthn.standalone.js b/examples/simple-demo/trusona-webauthn.standalone.js index 2696567..2b38bf2 100644 --- a/examples/simple-demo/trusona-webauthn.standalone.js +++ b/examples/simple-demo/trusona-webauthn.standalone.js @@ -1 +1 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.trusona=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&new Set(this.knownUsers()).has(userIdentifier)};DefaultKnownUsersService.prototype.unknownUser=function(userIdentifier){return!this.knownUser(userIdentifier)};DefaultKnownUsersService.prototype.lastUser=function(){var _a;return window.atob((_a=localStorage.getItem(this.cid))!==null&&_a!==void 0?_a:"")};DefaultKnownUsersService.prototype.add=function(userIdentifier){if(userIdentifier.trim().length>0){this.currentUser(userIdentifier);if(this.unknownUser(userIdentifier)){var users=this.knownUsers();users.push(userIdentifier);if(users.length>this.max){var set_1=[];var idx_1=0;users.forEach(function(element){if(idx_1++>0){set_1.push(element)}});this.save(set_1)}else{this.save(users)}}}};DefaultKnownUsersService.prototype.currentUser=function(userIdentifier){localStorage.setItem(this.cid,window.btoa(userIdentifier))};DefaultKnownUsersService.prototype.save=function(users){localStorage.setItem(this.kid,window.btoa(JSON.stringify(users)))};DefaultKnownUsersService.prototype.knownUsers=function(){var _a;try{var json=localStorage.getItem(this.kid);return(_a=JSON.parse(window.atob(json!==null&&json!==void 0?json:"")))!==null&&_a!==void 0?_a:[]}catch(e){return[]}};return DefaultKnownUsersService}();exports.DefaultKnownUsersService=DefaultKnownUsersService;function initKnownUsersService(){var _a;return((_a=configuration_1.Initializer.configuration)===null||_a===void 0?void 0:_a.useLocalStorage)===true?new DefaultKnownUsersService:new NoOperationKnownUsersService}},{"../core/configuration":4}],9:[function(require,module,exports){"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value)})}return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})};var __generator=this&&this.__generator||function(thisArg,body){var _={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},f,y,t,g;return g={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0)}}},{}],12:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.create=create;exports.get=get;exports.schema=void 0;exports.supported=supported;function base64urlToBuffer(baseurl64String){const padding="==".slice(0,(4-baseurl64String.length%4)%4);const base64String=baseurl64String.replace(/-/g,"+").replace(/_/g,"/")+padding;const str=atob(base64String);const buffer=new ArrayBuffer(str.length);const byteView=new Uint8Array(buffer);for(let i=0;iconvert(conversionFn,schema2[0],v))}if(schema2 instanceof Object){const output={};for(const[key,schemaField]of Object.entries(schema2)){if(schemaField.derive){const v=schemaField.derive(input);if(v!==void 0){input[key]=v}}if(!(key in input)){if(schemaField.required){throw new Error(`Missing key: ${key}`)}continue}if(input[key]==null){output[key]=null;continue}output[key]=convert(conversionFn,schemaField.schema,input[key])}return output}}function derived(schema2,derive){return{required:true,schema:schema2,derive:derive}}function required(schema2){return{required:true,schema:schema2}}function optional(schema2){return{required:false,schema:schema2}}var publicKeyCredentialDescriptorSchema={type:required(copyValue),id:required(convertValue),transports:optional(copyValue)};var simplifiedExtensionsSchema={appid:optional(copyValue),appidExclude:optional(copyValue),credProps:optional(copyValue)};var simplifiedClientExtensionResultsSchema={appid:optional(copyValue),appidExclude:optional(copyValue),credProps:optional(copyValue)};var credentialCreationOptions={publicKey:required({rp:required(copyValue),user:required({id:required(convertValue),name:required(copyValue),displayName:required(copyValue)}),challenge:required(convertValue),pubKeyCredParams:required(copyValue),timeout:optional(copyValue),excludeCredentials:optional([publicKeyCredentialDescriptorSchema]),authenticatorSelection:optional(copyValue),attestation:optional(copyValue),extensions:optional(simplifiedExtensionsSchema)}),signal:optional(copyValue)};var publicKeyCredentialWithAttestation={type:required(copyValue),id:required(copyValue),rawId:required(convertValue),authenticatorAttachment:optional(copyValue),response:required({clientDataJSON:required(convertValue),attestationObject:required(convertValue),transports:derived(copyValue,response=>{var _a;return((_a=response.getTransports)==null?void 0:_a.call(response))||[]})}),clientExtensionResults:derived(simplifiedClientExtensionResultsSchema,pkc=>pkc.getClientExtensionResults())};var credentialRequestOptions={mediation:optional(copyValue),publicKey:required({challenge:required(convertValue),timeout:optional(copyValue),rpId:optional(copyValue),allowCredentials:optional([publicKeyCredentialDescriptorSchema]),userVerification:optional(copyValue),extensions:optional(simplifiedExtensionsSchema)}),signal:optional(copyValue)};var publicKeyCredentialWithAssertion={type:required(copyValue),id:required(copyValue),rawId:required(convertValue),authenticatorAttachment:optional(copyValue),response:required({clientDataJSON:required(convertValue),authenticatorData:required(convertValue),signature:required(convertValue),userHandle:required(convertValue)}),clientExtensionResults:derived(simplifiedClientExtensionResultsSchema,pkc=>pkc.getClientExtensionResults())};var schema=exports.schema={credentialCreationOptions:credentialCreationOptions,publicKeyCredentialWithAttestation:publicKeyCredentialWithAttestation,credentialRequestOptions:credentialRequestOptions,publicKeyCredentialWithAssertion:publicKeyCredentialWithAssertion};function createRequestFromJSON(requestJSON){return convert(base64urlToBuffer,credentialCreationOptions,requestJSON)}function createResponseToJSON(credential){return convert(bufferToBase64url,publicKeyCredentialWithAttestation,credential)}async function create(requestJSON){const credential=await navigator.credentials.create(createRequestFromJSON(requestJSON));return createResponseToJSON(credential)}function getRequestFromJSON(requestJSON){return convert(base64urlToBuffer,credentialRequestOptions,requestJSON)}function getResponseToJSON(credential){return convert(bufferToBase64url,publicKeyCredentialWithAssertion,credential)}async function get(requestJSON){const credential=await navigator.credentials.get(getRequestFromJSON(requestJSON));return getResponseToJSON(credential)}function supported(){return!!(navigator.credentials&&navigator.credentials.create&&navigator.credentials.get&&window.PublicKeyCredential)}},{}]},{},[1])(1)}); +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.trusona=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0&&new Set(this.knownUsers()).has(userIdentifier)};DefaultKnownUsersService.prototype.unknownUser=function(userIdentifier){return!this.knownUser(userIdentifier)};DefaultKnownUsersService.prototype.lastUser=function(){var _a;return window.atob((_a=localStorage.getItem(this.cid))!==null&&_a!==void 0?_a:"")};DefaultKnownUsersService.prototype.add=function(userIdentifier){if(userIdentifier.trim().length>0){this.currentUser(userIdentifier);if(this.unknownUser(userIdentifier)){var users=this.knownUsers();users.push(userIdentifier);if(users.length>this.max){var set_1=[];var idx_1=0;users.forEach(function(element){if(idx_1++>0){set_1.push(element)}});this.save(set_1)}else{this.save(users)}}}};DefaultKnownUsersService.prototype.currentUser=function(userIdentifier){localStorage.setItem(this.cid,window.btoa(userIdentifier))};DefaultKnownUsersService.prototype.save=function(users){localStorage.setItem(this.kid,window.btoa(JSON.stringify(users)))};DefaultKnownUsersService.prototype.knownUsers=function(){var _a;try{var json=localStorage.getItem(this.kid);return(_a=JSON.parse(window.atob(json!==null&&json!==void 0?json:"")))!==null&&_a!==void 0?_a:[]}catch(e){return[]}};return DefaultKnownUsersService}();exports.DefaultKnownUsersService=DefaultKnownUsersService;function initKnownUsersService(){var _a;return((_a=configuration_1.Initializer.configuration)===null||_a===void 0?void 0:_a.useLocalStorage)===true?new DefaultKnownUsersService:new NoOperationKnownUsersService}},{"../core/configuration":4}],9:[function(require,module,exports){"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value)})}return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})};var __generator=this&&this.__generator||function(thisArg,body){var _={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},f,y,t,g;return g={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]0)}}},{}],12:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.create=create;exports.get=get;exports.schema=void 0;exports.supported=supported;function base64urlToBuffer(baseurl64String){const padding="==".slice(0,(4-baseurl64String.length%4)%4);const base64String=baseurl64String.replace(/-/g,"+").replace(/_/g,"/")+padding;const str=atob(base64String);const buffer=new ArrayBuffer(str.length);const byteView=new Uint8Array(buffer);for(let i=0;iconvert(conversionFn,schema2[0],v))}if(schema2 instanceof Object){const output={};for(const[key,schemaField]of Object.entries(schema2)){if(schemaField.derive){const v=schemaField.derive(input);if(v!==void 0){input[key]=v}}if(!(key in input)){if(schemaField.required){throw new Error(`Missing key: ${key}`)}continue}if(input[key]==null){output[key]=null;continue}output[key]=convert(conversionFn,schemaField.schema,input[key])}return output}}function derived(schema2,derive){return{required:true,schema:schema2,derive:derive}}function required(schema2){return{required:true,schema:schema2}}function optional(schema2){return{required:false,schema:schema2}}var publicKeyCredentialDescriptorSchema={type:required(copyValue),id:required(convertValue),transports:optional(copyValue)};var simplifiedExtensionsSchema={appid:optional(copyValue),appidExclude:optional(copyValue),credProps:optional(copyValue)};var simplifiedClientExtensionResultsSchema={appid:optional(copyValue),appidExclude:optional(copyValue),credProps:optional(copyValue)};var credentialCreationOptions={publicKey:required({rp:required(copyValue),user:required({id:required(convertValue),name:required(copyValue),displayName:required(copyValue)}),challenge:required(convertValue),pubKeyCredParams:required(copyValue),timeout:optional(copyValue),excludeCredentials:optional([publicKeyCredentialDescriptorSchema]),authenticatorSelection:optional(copyValue),attestation:optional(copyValue),extensions:optional(simplifiedExtensionsSchema)}),signal:optional(copyValue)};var publicKeyCredentialWithAttestation={type:required(copyValue),id:required(copyValue),rawId:required(convertValue),authenticatorAttachment:optional(copyValue),response:required({clientDataJSON:required(convertValue),attestationObject:required(convertValue),transports:derived(copyValue,response=>{var _a;return((_a=response.getTransports)==null?void 0:_a.call(response))||[]})}),clientExtensionResults:derived(simplifiedClientExtensionResultsSchema,pkc=>pkc.getClientExtensionResults())};var credentialRequestOptions={mediation:optional(copyValue),publicKey:required({challenge:required(convertValue),timeout:optional(copyValue),rpId:optional(copyValue),allowCredentials:optional([publicKeyCredentialDescriptorSchema]),userVerification:optional(copyValue),extensions:optional(simplifiedExtensionsSchema)}),signal:optional(copyValue)};var publicKeyCredentialWithAssertion={type:required(copyValue),id:required(copyValue),rawId:required(convertValue),authenticatorAttachment:optional(copyValue),response:required({clientDataJSON:required(convertValue),authenticatorData:required(convertValue),signature:required(convertValue),userHandle:required(convertValue)}),clientExtensionResults:derived(simplifiedClientExtensionResultsSchema,pkc=>pkc.getClientExtensionResults())};var schema=exports.schema={credentialCreationOptions:credentialCreationOptions,publicKeyCredentialWithAttestation:publicKeyCredentialWithAttestation,credentialRequestOptions:credentialRequestOptions,publicKeyCredentialWithAssertion:publicKeyCredentialWithAssertion};function createRequestFromJSON(requestJSON){return convert(base64urlToBuffer,credentialCreationOptions,requestJSON)}function createResponseToJSON(credential){return convert(bufferToBase64url,publicKeyCredentialWithAttestation,credential)}async function create(requestJSON){const credential=await navigator.credentials.create(createRequestFromJSON(requestJSON));return createResponseToJSON(credential)}function getRequestFromJSON(requestJSON){return convert(base64urlToBuffer,credentialRequestOptions,requestJSON)}function getResponseToJSON(credential){return convert(bufferToBase64url,publicKeyCredentialWithAssertion,credential)}async function get(requestJSON){const credential=await navigator.credentials.get(getRequestFromJSON(requestJSON));return getResponseToJSON(credential)}function supported(){return!!(navigator.credentials&&navigator.credentials.create&&navigator.credentials.get&&window.PublicKeyCredential)}},{}]},{},[1])(1)});