代码之家  ›  专栏  ›  技术社区  ›  Inzamam Malik

服务器到服务器身份验证失败-firebase-dialogflow-google上的操作-用户实体v2

  •  4
  • Inzamam Malik  · 技术社区  · 6 年前

    下面是我用来获取访问令牌的代码,用于创建会话实体,如下所述: https://dialogflow.com/docs/reference/api-v2/rest/v2/projects.agent.sessions.entityTypes 以前代码在工作,但突然停止工作,现在返回的访问令牌在FireBase函数中未定义,以下是不工作的代码:

    export const rough = functions.https.onRequest((request, response) => {
    
    var { google } = require('googleapis');
    
    const cred = {
        serviceAccountEmail: "dialogflow-abc@abc-abc.iam.gserviceaccount.com",
        privateKey: "-----BEGIN PRIVATE KEY-----abcdkey---END PRIVATE KEY-----\n"
    }
    
    // getting server to server OAuth token
    const serviceAccountAuth = new google.auth.JWT({ // key is private key, extracted from service-account json file
        email: cred.serviceAccountEmail,
        key: cred.privateKey,
        scopes: ['https://www.googleapis.com/auth/cloud-platform']
    })
    
    console.log(serviceAccountAuth);
    const _tokenData = serviceAccountAuth.authorize().then(tokenData => {
        console.log("tokenData: ", tokenData)
    }) })
    

    代码是正确的,因为 这个代码在我的机器上仍能正常工作 看看:

    我的机器代码:(工作)

    enter image description here enter image description here

    firebase函数中的相同代码:(不工作)

    enter image description here enter image description here

    如果我在FireBase函数仿真器中运行这个相同的函数,它就可以正常工作。

    本地仿真器(工作)

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  0
  •   Inzamam Malik    6 年前

    我的代码像以前一样自动开始工作 这是因为谷歌的一个事件

    调查FireBase的云功能问题

    事件开始于2018-12-15 04:00,结束于2018-12-15 13:15(全部 时代是美国/太平洋)。 https://status.firebase.google.com/incident/Functions/18044

    现在事件被回滚,这就是我相信我的代码再次开始正常工作的原因。

    当我在其他几个地方发布这个问题时,包括他们的slack channel和FireBase和Google API的不同Github repo,我意识到我不是唯一一个面临这个问题的人,在不同的服务(如函数和存储)中有更多的人报告类似的问题,他们的代码运行良好,但现在它正在抛出错误

    enter image description here

    enter image description here

    推荐文章