通过Node.js中的OAuth2对BigQuery REST API进行身份验证 [英] Authenticating to BigQuery REST API via OAuth2 from Node.js

查看:121
本文介绍了通过Node.js中的OAuth2对BigQuery REST API进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新手试图弄清楚如何让Node.js应用程序对Google BigQuery进行身份验证和查询,试图修改来自Java的这个CodeLab教程

首先我使用我的客户创建这个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帐户的权限。


同意生成第二个提示:


Nodejs_Test正在请求许可:
在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:需要登录,
locationType:header,$ b $location:Authorization


code:401,
message:需要登录
}
}

我知道你不能重复代码,因为权限,过期令牌等。但是我想知道我可能在概念上缺少什么步骤。

解决方案

您是否尝试过se将accesstoken作为授权头文件而不是url参数?



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


Newbie trying to figure out how to get a Node.js application to authenticate and query Google BigQuery, trying to adapt this CodeLab tutorial from Java. What step might i be missing?

First I create this Oauth2 URL using my clientid:

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

This successfully reaches Google, which prompts

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

Agreeing that generates a second prompt:

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

Agreeing to that, the callback URL is called, with a parameter accessToken.

I think the following url should list tables in my BigQuery project/dataset:

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

But calling with or without the accessToken returns the following message that "Login Required".

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

I know you can't repeat the code because of permissions, expired tokens, etc. But I wonder what step I might be missing conceptually.

解决方案

Have you tried sending the accesstoken as an authorization header rather than as a url parameter?

as in

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

这篇关于通过Node.js中的OAuth2对BigQuery REST API进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆