     private static var oauthSwift: OAuth2Swift?
 
     static func callbackURL(for loginService: LoginService, at server: URL) -> URL? {
-        guard let service = loginService.service else { return nil }
-        return URL(string: "https://\(server.host ?? "")/_oauth/\(service)")
+        guard
+            let service = loginService.service,
+            let host = server.host
+        else {
+            return nil
+        }
+
+        return URL(string: "https://\(host)/_oauth/\(service)")
+    }
+
+    static func state() -> String? {
+        return "{\"loginStyle\":\"popup\",\"credentialToken\":\"\(String.random(40))\",\"isCordova\":true}".base64Encoded()
     }
 
     static func authorize(loginService: LoginService, at server: URL, viewController: UIViewController, success: @escaping (OAuthCredentials) -> Void, failure: @escaping () -> Void) {

            let clientId = loginService.clientId,
            let authorizePath = loginService.authorizePath,
            let tokenPath = loginService.tokenPath,
            let callbackURL = callbackURL(for: loginService, at: server)
        else {
            return
        }


        }
        oauthSwift.authorizeURLHandler = handler

        oauthSwift.authorize(withCallbackURL: callbackURL, scope: scope,
                             state: state, success: { _, _, _  in }, failure: { _ in failure() })
    }
}
