oAuthenticate(passive) {
      return this.ready.then(() => {
        if (this.isAuthenticated()) {
          return Promise.resolve();
        }

        return new Promise((resolve, reject) => {
          var id = this.id.toLowerCase();

          if (passive) {
            this.accessToken = localStorage["mavo:".concat(id, "token")];

            if (this.accessToken) {
              resolve(this.accessToken);
            }
          } else {
            // Show window
            var popup = {
              width: Math.min(1000, innerWidth - 100),
              height: Math.min(800, innerHeight - 100)
            };
            popup.top = (screen.height - popup.height) / 2;
            popup.left = (screen.width - popup.width) / 2;
            var state = {
              url: location.href,
              backend: this.id
            };
            this.authPopup = open("".concat(this.constructor.oAuth, "?client_id=").concat(this.key, "&state=").concat(encodeURIComponent(JSON.stringify(state))) + this.oAuthParams(), "popup", "width=".concat(popup.width, ",height=").concat(popup.height, ",left=").concat(popup.left, ",top=").concat(popup.top));

            if (!this.authPopup) {
              var message = "Login popup was blocked! Please check your popup blocker settings.";
              this.mavo.error(message);
              reject(Error(message));
            }

            addEventListener("message", evt => {
              if (evt.source === this.authPopup) {
                if (evt.data.backend == this.id) {
                  this.accessToken = localStorage["mavo:".concat(id, "token")] = evt.data.token;
                }

                if (!this.accessToken) {
                  reject(Error("Authentication error"));
                }

                resolve(this.accessToken); // Log in to other similar backends that are logged out

                for (var appid in Mavo.all) {
                  var storage = Mavo.all[appid].primaryBackend;

                  if (storage && storage.id === this.id && storage !== this && !storage.isAuthenticated()) {
                    storage.login(true);
                  }
                }
              }
            });
          }
        });
      });
    }
Helper method for authenticating in OAuth APIs