js中的OAuth2对BigQuery

js中的OAuth2对BigQuery

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

问题描述

新手试图弄清楚如何让Node.js应用程序对Google BigQuery进行身份验证和查询,试图修改。

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

这成功地到达了谷歌,它提示

同意生成第二个提示:

同意,回调网址为名为 accessToken



我认为下面的url应该列出表格在我的BigQuery项目/数据集中:



但是,使用或不使用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

Agreeing that generates a second prompt:

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进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:09