Handle Authentication Challenge 01/203001/3
authorsurya.kumar7 <surya.kumar7@samsung.com>
Mon, 8 Apr 2019 15:24:55 +0000 (20:54 +0530)
committersurya.kumar7 <surya.kumar7@samsung.com>
Thu, 11 Apr 2019 08:21:25 +0000 (13:51 +0530)
Added support to gather and submit login info if server is
requesting for authentication for Tizen web apps

Depends on: https://review.tizen.org/gerrit/203000

Change-Id: I17ea4fefb7ece078bef1d6cf2499078e36122f79
Signed-off-by: surya.kumar7 <surya.kumar7@samsung.com>
wrt_app/src/web_application.js

index ae0cfc3a71f552528546a727c12756d8a84a0ccc..789d2d06a5bd98dd50e5ee196eb8d7203e4a6f9e 100755 (executable)
@@ -100,6 +100,18 @@ class WebApplication {
                 self.pendingCallbacks.delete(id);
             }
         });
+        wrt.on('auth-response', function(event, id, submit, user, passwd) {
+            let callback = self.pendingCallbacks.get(id);
+            if (typeof callback === 'function') {
+                console.log('calling auth response callback');
+                if (submit) {
+                    callback(user, passwd);
+                } else {
+                    callback();
+                }
+                self.pendingCallbacks.delete(id);
+            }
+        });
         app.on('certificate-error', function(event, webContents, url, error, certificate, callback) {
             console.log('A certificate error has occurred');
             event.preventDefault();
@@ -132,6 +144,14 @@ class WebApplication {
             const ses = webContents.session;
             ses.setPermissionRequestHandler(handlePermissionRequests);
         });
+        app.on('login', function(event, webContents, request, authInfo, callback) {
+            console.log('Login info is required');
+            event.preventDefault();
+            const id = ++self.pendingID;
+            console.log(`Raising a login info request with id: ${id}`);
+            self.pendingCallbacks.set(id, callback);
+            wrt.handleAuthRequest(id, webContents);
+        });
     }
     suspend() {
         console.log('WebApplication : suspend');