 
 import UIKit
 import MobileCoreServices
+import OnePasswordExtension
 
 public struct MultiAuthService {
     


private extension MultiAuthService {
    
    func configuredActivityViewController(URLString: String, sender: AnyObject, handler: (username: String?, password: String?, errorMessage: String?) -> ()) -> UIActivityViewController {
        let item = [MultiAuthService.URLStringKey: URLString]
        let itemProvider = NSItemProvider(item: item, typeIdentifier: MultiAuthService.findLoginAction)
        let extensionItem = NSExtensionItem()
        extensionItem.attachments = [itemProvider]
        let keychainActivity = KeychainActivity()
        keychainActivity.handler = handler
        let activityViewController = UIActivityViewController(activityItems: [extensionItem], applicationActivities: [keychainActivity])
        if let barButtonItem = sender as? UIBarButtonItem {
            activityViewController.popoverPresentationController?.barButtonItem = barButtonItem
        } else if let senderView = sender as? UIView {
            activityViewController.popoverPresentationController?.sourceView = senderView.superview
            activityViewController.popoverPresentationController?.sourceRect = senderView.frame
        }
        return activityViewController
    }
    
    static func didRecordLogInViaSharedCredentials() -> Bool {
        return NSUserDefaults.standardUserDefaults().boolForKey(logInViaSharedCredentialsKey)
    }

    // MARK: - Public API
        
    public func retrieveCredentialsFromActivityViewController(urlString: String, fromViewController viewController: UIViewController, sender: AnyObject, storedHandler: (username: String?, password: String?, errorMessage: String?) -> ()) {
        let keychainActivity = KeychainActivity()
        keychainActivity.handler = storedHandler
        
        onePasswordExtension.findLoginForURLString(urlString, forViewController: viewController, sender: sender, applicationActivities: [keychainActivity]) { loginDictionary, error in
            if let loginDictionary = loginDictionary where error == nil {
                let username = loginDictionary[AppExtensionUsernameKey] as? String
                let password = loginDictionary[AppExtensionPasswordKey] as? String
                storedHandler(username: username, password: password, errorMessage: nil)
            } else {
                storedHandler(username: nil, password: nil, errorMessage: error?.localizedDescription)
            }
        }
    }
    
    public func saveSharedCredentials(username username: String, password: String) {
