Angular-我可以使用AngularFireAuth来授权GCP API吗?

时间:2020-04-29 15:26:43

标签: node.js angular firebase oauth google-drive-api

想重新发布此问题,因为以前有点罗

我在将Google Drive API与我的第一个Angular项目之一合并时遇到了很多麻烦。我非常喜欢Firebase提供的简单界面,以允许用户登录我的应用程序,但是现在我想使用Drive API,Node.js quick start guide希望我使用“授权的OAuth2客户端”进行访问用户数据:

 * Lists the names and IDs of up to 10 files.
 * @param {google.auth.OAuth2} auth An authorized OAuth2 client.
 */
function listFiles(auth) {
  const drive = google.drive({version: 'v3', auth});
  drive.files.list({
    pageSize: 10,
    fields: 'nextPageToken, files(id, name)',
  }, (err, res) => {
    if (err) return console.log('The API returned an error: ' + err);
    const files = res.data.files;
    if (files.length) {
      console.log('Files:');
      files.map((file) => {
        console.log(`${file.name} (${file.id})`);
      });
    } else {
      console.log('No files found.');
    }
  });
}

我是否可以使用Firebase获取OAuth2访问令牌以验证Google Drive API?我已经在身份验证请求中添加了必需的访问范围,但似乎找不到在AngularFireAuth中检索访问令牌的方法。我也不知道是否将此令牌传递到上面的代码中。

0 个答案:

没有答案