node.js - 通过 OAuth2 从 Node.js 向 BigQuery REST API 进行身份验证

标签 node.js oauth-2.0 google-bigquery

新手试图找出如何让 Node.js 应用程序来验证和查询 Google BigQuery,试图适应 this CodeLab tutorial from Java 。我可能缺少哪一步?

首先,我使用我的 clientid 创建此 Oauth2 URL:

https://accounts.google.com/o/oauth2/auth?
    client_id=1047877053699-den6kbs4v3f2bft6clonsirkj1pc7t6j.apps.googleusercontent.com
    &scope=https://www.googleapis.com/auth/bigquery
    &redirect_uri=http://localhost:3000/oauth2callback
    &access_type=offline
    &response_type=code

这已成功到达 Google,并出现提示

A third party service is requesting permission to access your Google Account.

同意生成第二个提示:

Nodejs_Test is requesting permission to: View and manage your data in Google BigQuery

同意这一点,将使用参数 accessToken 调用回调 URL。

认为以下网址应列出我的 BigQuery 项目/数据集中的表:

https://www.googleapis.com/bigquery/v2/projects/1047877053699/datasets/visits&accessToken=4%2FC196NizZwlNgWSt5oNqQwendmLNW.0vgUrlGJ6kMRshQV0ieZDApig3NfcgI

但是使用或不使用 accessToken 进行调用都会返回以下消息:“需要登录”。

 {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

我知道由于权限、过期 token 等原因,您无法重复代码。但我想知道我在概念上可能缺少哪一步。

最佳答案

您是否尝试过将 accesstoken 作为授权 header 而不是作为 url 参数发送?

https://www.googleapis.com/bigquery/v2/projects/1047877053699/datasets/visits
Authorization: OAuth Your-access-token-here-not-urlencoded

关于node.js - 通过 OAuth2 从 Node.js 向 BigQuery REST API 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11989001/

相关文章:

oauth-2.0 - google oAuth - 从 google oAuth 登录后如何删除 cookie

django - 无法为 API 设置 'oauth2_provider.ext.rest_framework.OAuth2Authentication' 导入 'DEFAULT_AUTHENTICATION_CLASSES'

google-bigquery 有没有办法复制表并在原始表更新时更新它?

sql - BigQuery 模运算符 (%) 在 WHERE 子句中不起作用

node.js - FeathersJS客户端如何知道服务路径是否无效?

node.js - 如何在 express 中设置默认路径(路由前缀)?

mysql - Nodejs JOIN 查询 : formatting JSON output

javascript - Node.js 单线程机制

c# - 将自定义参数传递给 Identity Server 3

SQL 根据最大​​索引选择唯一名称