document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  async registerUser(username: string, name: string) {
  2.     this.getMakeCredentialsChallenge({username, name}) //Client sends the user’s data to the server - Ends step 1
  3.       .then(response => { //Begins step 3
  4.         let publicKey;
  5.  
  6.         if (response.success) {
  7.        //The Client decrypts the challenge and user ID generating an object
  8.           publicKey = this.preformatMakeCredReq({
  9.             status: response.status,
  10.             challenge: response.challenge,
  11.             rp: response.rp,
  12.             user: response.user,
  13.             attestation: response.attestation,
  14.             pubKeyCredParams: response.pubKeyCredParams,
  15.           });        
  16. }
  17.  
  18.         return (navigator as any).credentials.create({publicKey}); //Here the browser asks the user to use a valid authenticator - Ends step 3
  19.       })
  20.       .then(response => { //Begins step 5
  21.         const makeCredResponse = this.publicKeyCredentialToJSON(response); //Generates the object to respond with the result of the interaction between the user and the authenticator
  22.  
  23.         return this.sendWebAuthnResponse(makeCredResponse); //It is sent to the server
  24.       }) //Ends step 5
  25.       .then(response => { //The server verifies that everything is ok
  26.         if ((response as any).rawResponse.data.status === "ok") {
  27.           this.loadMainContainerRegister();
  28.         } else {
  29.           alert(`Server responed with error. The message is: ${(response as any).rawResponse.data.message}`);
  30.         }
  31.       })
  32.       .catch(error => alert(error));
  33.   }
');