连接到GoogleApis时范围无效

时间:2019-08-23 19:38:21

标签: node.js authentication google-api

接收

https://appengine.googleapis.com/auth/appengine.admin不是有效的受众字符串。尝试编写node.js脚本以从Google Cloud环境中检索信息时发生错误。

我尝试重新制作网址并在此处{@ {3}}

检查Google提供的当前网址。

以及此处:https://cloud.google.com/appengine/docs/admin-api/accessing-the-api#configuring_your_project_and_creating_credentials

两者都显示以下URL:

https://www.googleapis.com/auth/appengine.admin
https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/cloud-platform.read-only

这是我的代码

const { JWT } = require('google-auth-library')
const { google } = require('googleapis')
const keys = process.env.NODE_ENV === 'production' ? process.env.GOOGLE_KEY : require('./.google-auth-keyfile.json');
const config = require('/config.json')
const appengine = google.appengine({ version: 'v1' })

const scopes = [
    'https://www.googleapis.com/auth/appengine',
    'https://www.googleapis.com/auth/cloud-platform.read-only',
    'https://www.googleapis.com/auth/cloudplatform'
]


const jwtClient = new google.auth.JWT(
    keys.client_email,
    null,
    keys.private_key,
    scopes,
    config.impersonate
);

jwtClient.authorize()

appengine.apps.authorizedCertificates.list({
    appsId: config.application,
    auth: jwtClient,
    domain: config.domain
}).then(res => {
    console.log(res)
}).catch(err => {
    console.log(err)
})

完全错误

(node:4012) UnhandledPromiseRejectionWarning: Error: invalid_scope: https://appengine.googleapis.com/auth/appengine.admin is not a valid audience string.
    at Gaxios.request (D:\_GIT\hos\restart-appengine\node_modules\gaxios\build\src\gaxios.js:70:23)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:4012) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4012) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
{ Error: invalid_scope: https://appengine.googleapis.com/auth/appengine.admin is not a valid audience string.
    at Gaxios.request (D:\_GIT\hos\restart-appengine\node_modules\gaxios\build\src\gaxios.js:70:23)
    at process._tickCallback (internal/process/next_tick.js:68:7)

0 个答案:

没有答案