NodeJS 中的无缝 Google 授权

问题描述

我的应用程序是一个事件管理系统,我想将事件链接用户的 Google 日历。我已经尝试在 npm 上使用 googleapis 来检索刷新令牌,但这需要有人在终端上单击链接并从他们的文档中输入重定向 URL 中的代码

// in nodejs
const authUrl = oauth2client.generateAuthUrl({
      access_type: "offline",scope: ScopES,});

    console.log("Authorize this app by visiting this url:",authUrl);
    const rl = readline.createInterface({
      input: process.stdin,output: process.stdout,});

    rl.question("Enter the code from that page here: ",(code) => {
      rl.close();
      oauth2client.getToken(code,async (err,token) => {
        if (err) return console.error("Error retrieving access token",err);
        oauth2client.setCredentials(token);

        // store in database

        callback(oauth2client);
      });
    });

如果我不将access_type设置为离线,我相信它会导致访问令牌在一个小时内再次需要重新授权,这不是我想要的。

是否有一种不需要交互的自动方式来获取一组凭据(使用或不使用此包)?

或者,有没有办法通过前端 (ReactJS) 获取所需的凭据(OAuth 刷新令牌)?那里的大多数材料似乎都需要重新授权。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)