Javascript Google OAuth2登录总是要求用户访问权限

Javascript Google OAuth2登录总是要求用户访问权限,javascript,reactjs,electron,google-authentication,Javascript,Reactjs,Electron,Google Authentication,注意我在这个主题上发现了很多类似的问题,但没有一个是有帮助的,所以我决定用代码问一个问题 例如 我正在使用Electron桌面应用程序,用户通过Google auth及其Google帐户进行身份验证 问题是,每次注销时,用户都会被要求允许对应用程序的访问权限 onLogin = async () => { if (!this.state.config || this.authWindow) return; try { const code = await thi

注意我在这个主题上发现了很多类似的问题,但没有一个是有帮助的,所以我决定用代码问一个问题 例如

我正在使用Electron桌面应用程序,用户通过Google auth及其Google帐户进行身份验证

问题是,每次注销时,用户都会被要求允许对应用程序的访问权限

onLogin = async () => {
    if (!this.state.config || this.authWindow) return;
    try {
      const code = await this.openLoginWindow();
      const { data } = await this.getAccessToken(code);
      this.onGoogleLoginSuccess(data.id_token);
    } catch(err) {
      log.error(err);
      this.onGoogleLoginFailure();
    }
  }

openLoginWindow = () => {
    return new Promise((resolve, reject) => {
      const { isDev, ELECTRON_GOOGLE_ID } = this.state.config;

      const authWindow = this.authWindow = new electron.remote.BrowserWindow({
        width: 500,
        height: 600,
        show: true,
        parent: electron.remote.getCurrentWindow(),
        modal: true
      })

      if (!isDev) {
        authWindow.webContents.session.cookies.remove('https://accounts.google.com', 'SID', () => {});
      }

      const urlParams = {
        response_type: 'code',
        redirect_uri: GOOGLE_REDIRECT_URI,
        client_id: ELECTRON_GOOGLE_ID,
        scope: 'profile email',
      }

      authWindow.webContents.on('will-navigate', (event, url) => {
        this.onRedirect(url, authWindow, resolve, reject);
      });

      authWindow.webContents.on('did-get-redirect-request', (event, oldUrl, newUrl) => {
        this.onRedirect(newUrl, authWindow, resolve, reject);
      });

      authWindow.webContents.on('will-redirect', (event, url) => {
        this.onRedirect(url, authWindow, resolve, reject);
      });

      authWindow.on('close', () => this.authWindow = null);

      authWindow.loadURL(`${ GOOGLE_AUTHORIZATION_URL }?${ qs.stringify(urlParams) }`);
    });
  }

getAccessToken = code => {
    return axios.post(GOOGLE_TOKEN_URL, qs.stringify({
      code,
      client_id: this.state.config.ELECTRON_GOOGLE_ID,
      redirect_uri: GOOGLE_REDIRECT_URI,
      grant_type: 'authorization_code',
    }), {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      withCredentials: false
    })
  }
您是否看到此代码中有错误

const urlParams = {
        response_type: 'code',
        redirect_uri: GOOGLE_REDIRECT_URI,
        client_id: ELECTRON_GOOGLE_ID,
        scope: 'profile email',
        providerParams: {
         access_type: 'offline',
         prompt: 'select_account'
         }
      }

你能试一下使用这个urlparms对象吗?

不,还是一样的:/I我曾经遇到过类似的问题。但将promt类型从“同意”改为“选择账户”对我来说很有效。不知道为什么它在你的情况下不起作用。无论如何,我不确定它在电子应用程序中是如何工作的,我已经在一个web应用程序中对它进行了测试