             }
         }
         
+        self.currentCommand = command
+        self.currentNsObserver = observer
+        
         self.viewController.present(svc, animated: true)
     }
-}+    
+    func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
+        guard self.currentNsObserver != nil && self.currentCommand != nil else { return }
+        
+        let res = CDVPluginResult(
+            status: CDVCommandStatus_ERROR,
+            messageAs: [
+                "type": "auth_canceled",
+                "msg": "The user cancelled the authentication process."
+            ]
+        )
+        self.commandDelegate.send(res, callbackId: self.currentCommand!.callbackId)
+        
+        NotificationCenter.default.removeObserver(self.currentNsObserver!)
+        self.currentCommand = nil
+        self.currentNsObserver = nil
+    }
+}

            
            svc.presentingViewController!.dismiss(animated: true, completion: nil)
            NotificationCenter.default.removeObserver(observer!)
            
            auth.handleAuthCallback(withTriggeredAuthURL: url) { (err, sess) in
                guard err == nil else {

        auth.requestedScopes = command.argument(at: 3) as! Array
        
        let svc = SFSafariViewController(url: auth.spotifyWebAuthenticationURL())
        svc.delegate = self;
        svc.modalPresentationStyle = .overFullScreen
        
        var observer: NSObjectProtocol?
        observer = NotificationCenter.default.addObserver(
            forName: NSNotification.Name.CDVPluginHandleOpenURL,
