[java-idp-plugin-webauthn] branch main updated: Add isSupported function and message if not supported

Phil Smart philip.smart at jisc.ac.uk
Mon Jan 22 15:19:16 UTC 2024


This is an automated email from the git hooks/post-receive script.

philsmart pushed a commit to branch main
in repository java-idp-plugin-webauthn.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-webauthn.git;a=commit;h=9b291edbef4f62bbff42a949d9685a49c3d9a233

The following commit(s) were added to refs/heads/main by this push:
     new 9b291ed  Add isSupported function and message if not supported
9b291ed is described below

commit 9b291edbef4f62bbff42a949d9685a49c3d9a233
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Mon Jan 22 15:19:13 2024 +0000

    Add isSupported function and message if not supported
---
 .../plugin/authn/webauthn/views/webauthn-authn.vm  | 165 +++++++++++++--------
 .../authn/webauthn/views/webauthn-register.vm      | 138 +++++++++--------
 2 files changed, 179 insertions(+), 124 deletions(-)

diff --git a/webauthn-impl/src/main/resources/net/shibboleth/idp/plugin/authn/webauthn/views/webauthn-authn.vm b/webauthn-impl/src/main/resources/net/shibboleth/idp/plugin/authn/webauthn/views/webauthn-authn.vm
index 90cb141..1bc1b02 100644
--- a/webauthn-impl/src/main/resources/net/shibboleth/idp/plugin/authn/webauthn/views/webauthn-authn.vm
+++ b/webauthn-impl/src/main/resources/net/shibboleth/idp/plugin/authn/webauthn/views/webauthn-authn.vm
@@ -29,48 +29,71 @@
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0">
     <script type="text/javascript" src="$request.getContextPath()/js/webauthn-support.js"></script>
-    <link rel="stylesheet" type="text/css" href="$request.getContextPath()#springMessageText(" idp.css", "/css/placeholder.css" )">
+    <link rel="stylesheet" type="text/css" href="$request.getContextPath()#springMessageText("
+        idp.css", "/css/placeholder.css" )">
     <link rel="stylesheet" type="text/css" href="$request.getContextPath()/css/webauthn.css">
-    <script type="module">    
-    
-    import {
-          get,
-          parseRequestOptionsFromJSON,
-          supported,
-        }  from "$request.getContextPath()/js/webauthn/webauthn-json.browser-ponyfill.js";
-  
-     async function authenticate() {
+    <script type="module">
+
+        import {
+            get,
+            parseRequestOptionsFromJSON,
+            supported,
+        } from "$request.getContextPath()/js/webauthn/webauthn-json.browser-ponyfill.js";
+
+        async function authenticate() {
             var pkCredRequestOptions = $webauthnContext.publicKeyCredentialRequestOptionsJSON;
             var parsedRequestOptions = parseRequestOptionsFromJSON({ publicKey: pkCredRequestOptions });
             #if($debug == "true")
-                console.log("Raw request options", pkCredRequestOptions);
-                console.log("Parsed request options", parsedRequestOptions);
+            console.log("Raw request options", pkCredRequestOptions);
+            console.log("Parsed request options", parsedRequestOptions);
             #end
             await get(parsedRequestOptions)
-                .then(function (assertion){
+                .then(function (assertion) {
                     document.getElementById("publicKeyAssertion").value = JSON.stringify(assertion);
                     document.getElementById("authenticationSubmit").click();
-                }).catch(function (err){console.error(err)});    
+                }).catch(function (err) { console.error(err) });
+
+        }
 
-     }
+        function initButton() {
+            document.getElementById("authenticate").onclick = authenticate;
+            return false;
+        }
 
-     function init() {
-          document.getElementById("authenticate").onclick = authenticate;        
-          return false;
-     }
-  #if($debug == "true")   
-     window.onload = init;
-  #else
-    window.onload = authenticate;
-  #end
 
-</script>
+        window.addEventListener("load", () => {
+            try {
+                var isSupported = supported();
+                if (!isSupported) {
+                    document.getElementById('supportedDiv').classList.add('hidden')
+                    document.getElementById("supportedDiv").disabled = true;
+                    document.getElementById("authenticate").disabled = true;
+                    document.getElementById("authenticatorAssertionForm").disabled = true;
+                    document.getElementById("authenticationSubmit").disabled = true;
+
+                    document.getElementById("unsupportedDiv").disabled = false;
+                    document.getElementById('unsupportedDiv').classList.remove('hidden')
+                } else {
+                    #if($debug == "true")
+                    initButton();
+                    #else
+                    authenticate();
+                    #end
+                }
+
+            } catch (e) {
+                console.error(e);
+            }
+        });
+
+    </script>
 </head>
 
 <body>
     <main class="main">
         <header>
-            <img class="main-logo" src="$request.getContextPath()#springMessageText(" idp.logo", "/images/placeholder-logo.png" )" alt="#springMessageText(" idp.logo.alt-text", "logo" )" />
+            <img class="main-logo" src="$request.getContextPath()#springMessageText("
+                idp.logo", "/images/placeholder-logo.png" )" alt="#springMessageText(" idp.logo.alt-text", "logo" )" />
 
             #set ($serviceName = $rpUIContext.serviceName)
             #if ($serviceName && !$rpContext.getRelyingPartyId().contains($serviceName))
@@ -79,48 +102,60 @@
         </header>
 
         <section>
-                #*
-                //
-                //    SP Description & Logo (optional)
-                //    These idpui lines will display added information (if available
-                //    in the metadata) about the Service Provider (SP) that requested
-                //    authentication. These idpui lines are "active" in this example
-                //    (not commented out) - this extra SP info will be displayed.
-                //    Remove or comment out these lines to stop the display of the
-                //    added SP information.
-                //
-                *#
-                #set ($logo = $rpUIContext.getLogo())
-                #if ($logo)
-                    <img class="service-logo" src= "$encoder.encodeForHTMLAttribute($logo)" alt="$encoder.encodeForHTMLAttribute($serviceName)">
-                #end
-                #set ($desc = $rpUIContext.getServiceDescription())
-                #if ($desc)
-                    <p>$encoder.encodeForHTML($desc)</p>
-                #end
-
-            <div class="content">
-                <div class="column one">
-                    <form id="authn-form" action="$flowExecutionUrl" method="post">
-                        #parse("csrf/csrf.vm")
-                        <input type="hidden" id="publicKeyAssertion" name="publicKeyAssertion"/>
-                        <button class="hidden" id="authenticationSubmit" type="submit" name="_eventId_proceed">#springMessageText("idp.webauthn.authn.submit", "Submit Authentication")</button>
-                    </form>
-                    #if($debug == "true")
+            #*
+            //
+            // SP Description & Logo (optional)
+            // These idpui lines will display added information (if available
+            // in the metadata) about the Service Provider (SP) that requested
+            // authentication. These idpui lines are "active" in this example
+            // (not commented out) - this extra SP info will be displayed.
+            // Remove or comment out these lines to stop the display of the
+            // added SP information.
+            //
+            *#
+            #set ($logo = $rpUIContext.getLogo())
+            #if ($logo)
+            <img class="service-logo" src="$encoder.encodeForHTMLAttribute($logo)"
+                alt="$encoder.encodeForHTMLAttribute($serviceName)">
+            #end
+            #set ($desc = $rpUIContext.getServiceDescription())
+            #if ($desc)
+            <p>$encoder.encodeForHTML($desc)</p>
+            #end
+            <div id="supportedDiv">
+                <div class="content">
+                    <div class="column one">
+                        <form id="authenticatorAssertionForm" action="$flowExecutionUrl" method="post">
+                            #parse("csrf/csrf.vm")
+                            <input type="hidden" id="publicKeyAssertion" name="publicKeyAssertion" />
+                            <button class="hidden" id="authenticationSubmit" type="submit"
+                                name="_eventId_proceed">#springMessageText("idp.webauthn.authn.submit", "Submit
+                                Authentication")</button>
+                        </form>
+                        #if($debug == "true")
                         <div class="centre">
-                            <button id="authenticate" class="form-element form-button">#springMessageText("idp.webauthn.authn.authenticate", "Authenticate")</button>
-                        </div>                                           
-                        <hr/>
-                        <button type="button" class="collapsible">#springMessageText("idp.webauthn.debug.title", "Debugging")</button> 
-                        
+                            <button id="authenticate"
+                                class="form-element form-button">#springMessageText("idp.webauthn.authn.authenticate",
+                                "Authenticate")</button>
+                        </div>
+                        <hr />
+                        <button type="button" class="collapsible">#springMessageText("idp.webauthn.debug.title",
+                            "Debugging")</button>
+
                         <div class="debug" id="debug-div">
-                          <label for="publicKeyCredentialCreation">#springMessageText("idp.webauthn.debug.request", "Request Options")</label>
-                          <textarea id="publicKeyCredentialRequestOptions" name="publicKeyCredentialRequestOptions" rows="20" cols="50">
-                            $webauthnContext.publicKeyCredentialRequestOptions</textarea>
+                            <label for="publicKeyCredentialCreation">#springMessageText("idp.webauthn.debug.request",
+                                "Request Options")</label>
+                            <textarea id="publicKeyCredentialRequestOptions" name="publicKeyCredentialRequestOptions"
+                                rows="20" cols="50">
+                                $webauthnContext.publicKeyCredentialRequestOptions</textarea>
                         </div>
-                    #end
+                        #end
+                    </div>
                 </div>
-
+            </div>
+            </div>
+            <div id="unsupportedDiv" class="hidden">
+                #springMessageText("idp.webauthn.authn.unsupported", "Your browser is not WebAuthn compatible")
             </div>
         </section>
 
@@ -133,4 +168,4 @@
 
 </body>
 
-</html>
\ No newline at end of file
+</html>
diff --git a/webauthn-impl/src/main/resources/net/shibboleth/idp/plugin/authn/webauthn/views/webauthn-register.vm b/webauthn-impl/src/main/resources/net/shibboleth/idp/plugin/authn/webauthn/views/webauthn-register.vm
index 98d7822..a29d4a1 100644
--- a/webauthn-impl/src/main/resources/net/shibboleth/idp/plugin/authn/webauthn/views/webauthn-register.vm
+++ b/webauthn-impl/src/main/resources/net/shibboleth/idp/plugin/authn/webauthn/views/webauthn-register.vm
@@ -58,19 +58,35 @@
 
      };
 
-     function init() {
+     function initButton() {
           document.getElementById("registerButton").onclick = register;        
           return false;
      }
      
-     window.onload = init;
+     window.addEventListener("load", () => {
+  try {
+      var isSupported = supported();
+      if (!isSupported){
+        document.getElementById('supportedDiv').classList.add('hidden')
+        document.getElementById("supportedDiv").disabled = true;
+        document.getElementById("authenticatorAttestationForm").disabled = true;        
+        document.getElementById("registrationSubmit").disabled = true;
+        
+        document.getElementById("unsupportedDiv").disabled = false;
+        document.getElementById('unsupportedDiv').classList.remove('hidden')
+      } else{
+          initButton();
+      }     
+    
+  } catch (e) {
+    console.error(e);
+  }
+});
 
 </script>
   
 </head>
 
-
-
 <body>
 
     <main class="main">
@@ -83,65 +99,69 @@
     </header>
 
       <section>
-    
-        <div class="content">
-          <div class="column one centre"> 
-            <div>
-                <h1>Registered Keys</h1>
-                 #if ($webauthnRegContext.existingCredentials)
-                    <table>
-                        <tr>
-                            <th>#springMessageText("idp.webauthn.register.table.keyName", "Key Name")</th>
-                            <th>#springMessageText("idp.webauthn.register.table.transports", "Transports")</th>
-                            <th>#springMessageText("idp.webauthn.register.table.passkey", "Passkey?")</th>
-                            <th>#springMessageText("idp.webauthn.register.table.registrationTime", "Registration Time")</th>
-                            <th>#springMessageText("idp.webauthn.register.table.action", "Action")</th>
-                        </tr>
-                         #foreach($cred in $webauthnRegContext.existingCredentials)
+        <div id="supportedDiv">
+            <div class="content">
+              <div class="column one centre"> 
+                <div>
+                    <h1>Registered Keys</h1>
+                     #if ($webauthnRegContext.existingCredentials)
+                        <table>
                             <tr>
-                                <td>$encoder.encodeForHTML($cred.nickname)</td>
-                                <td>$encoder.encodeForHTML($cred.transportsString)</td>
-                                <td>$encoder.encodeForHTML($cred.discoverableAsString)</td>
-                                <td>$encoder.encodeForHTML($cred.registrationTimestamp)</td>
-                                <td>
-                                <form id="deleteKeyForm" action="$flowExecutionUrl" method="post">
-                                    #parse("csrf/csrf.vm")
-                                    <input type="hidden" name="credentialId" value="$cred.credentialIdBase64Url"/>
-                                    <button class="webauthn-table-button" id="removeButton" type="submit" name="_eventId_deleteKey">#springMessageText("idp.webauthn.register.credential.remove", "Remove")</button>
-                                </form>
-                                </td>
+                                <th>#springMessageText("idp.webauthn.register.table.keyName", "Key Name")</th>
+                                <th>#springMessageText("idp.webauthn.register.table.transports", "Transports")</th>
+                                <th>#springMessageText("idp.webauthn.register.table.passkey", "Passkey?")</th>
+                                <th>#springMessageText("idp.webauthn.register.table.registrationTime", "Registration Time")</th>
+                                <th>#springMessageText("idp.webauthn.register.table.action", "Action")</th>
                             </tr>
-                         #end   
-                    </table>
-                 #else
-                    <div><span>#springMessageText("idp.webauthn.register.registered.noKeys", "You have no registered keys")</span></div>                 
-                 #end
-                 <br/>
-                 <div>
-                    <button class="form-element form-button" id="registerButton">#springMessageText("idp.webauthn.register.addKey", "Add Key")</button>
-                 </div>
-                 
-                  <form id="authenticatorAttestationForm" action="$flowExecutionUrl" method="post">
-                      #parse("csrf/csrf.vm")
-                      <input type="hidden" id="credentialNickname" name="credentialNickname"/>
-                      <input type="hidden" id="authenticatorAttestation" name="authenticatorAttestation"/>
-                      <button class="hidden" id="registrationSubmit" type="submit" name="_eventId_addKey">#springMessageText("idp.webauthn.register.submit", "Submit Registration")</button>
-                  </form>
-            </div>
-            
-            #if($debug == "true")
-                <hr/>
-               
-                <button type="button" class="collapsible">#springMessageText("idp.webauthn.register.debug.title", "Debugging")</button> 
-                
-                <div class="debug" id="debug-div">
-                    <label for="publicKeyCredentialCreation">#springMessageText("idp.webauthn.register.debug.registration", "Registration Options")</label>
-                    <textarea id="publicKeyCredentialCreation" name="publicKeyCredentialCreation" rows="20" cols="50">
-                    $webauthnRegContext.publicKeyCredentialCreationOptions</textarea>                   
+                             #foreach($cred in $webauthnRegContext.existingCredentials)
+                                <tr>
+                                    <td>$encoder.encodeForHTML($cred.nickname)</td>
+                                    <td>$encoder.encodeForHTML($cred.transportsString)</td>
+                                    <td>$encoder.encodeForHTML($cred.discoverableAsString)</td>
+                                    <td>$encoder.encodeForHTML($cred.registrationTimestamp)</td>
+                                    <td>
+                                    <form id="deleteKeyForm" action="$flowExecutionUrl" method="post">
+                                        #parse("csrf/csrf.vm")
+                                        <input type="hidden" name="credentialId" value="$cred.credentialIdBase64Url"/>
+                                        <button class="webauthn-table-button" id="removeButton" type="submit" name="_eventId_deleteKey">#springMessageText("idp.webauthn.register.credential.remove", "Remove")</button>
+                                    </form>
+                                    </td>
+                                </tr>
+                             #end   
+                        </table>
+                     #else
+                        <div><span>#springMessageText("idp.webauthn.register.registered.noKeys", "You have no registered keys")</span></div>                 
+                     #end
+                     <br/>
+                     <div>
+                        <button class="form-element form-button" id="registerButton">#springMessageText("idp.webauthn.register.addKey", "Add Key")</button>
+                     </div>
+                     
+                      <form id="authenticatorAttestationForm" action="$flowExecutionUrl" method="post">
+                          #parse("csrf/csrf.vm")
+                          <input type="hidden" id="credentialNickname" name="credentialNickname"/>
+                          <input type="hidden" id="authenticatorAttestation" name="authenticatorAttestation"/>
+                          <button class="hidden" id="registrationSubmit" type="submit" name="_eventId_addKey">#springMessageText("idp.webauthn.register.submit", "Submit Registration")</button>
+                      </form>
                 </div>
-            #end
-    
+                
+                #if($debug == "true")
+                    <hr/>
+                   
+                    <button type="button" class="collapsible">#springMessageText("idp.webauthn.register.debug.title", "Debugging")</button> 
+                    
+                    <div class="debug" id="debug-div">
+                        <label for="publicKeyCredentialCreation">#springMessageText("idp.webauthn.register.debug.registration", "Registration Options")</label>
+                        <textarea id="publicKeyCredentialCreation" name="publicKeyCredentialCreation" rows="20" cols="50">
+                        $webauthnRegContext.publicKeyCredentialCreationOptions</textarea>                   
+                    </div>
+                #end
+        
+              </div>
           </div>
+           <div id="unsupportedDiv" class="hidden">
+                #springMessageText("idp.webauthn.register.unsupported", "Your browser is not WebAuthn compatible")
+            </div>
     
         </div>
       </section>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list