簡體   English   中英

關於谷歌智能家居令牌交換問題的行動

[英]Action on google Smart home token exchange problem

我陷入了困境。

情況:

我們在移動應用 IOS/Android 和 Action On Google(智能家居)中使用 Firebase 身份驗證。 我們使用 Firebase Function 來處理請求。

問題

在 google 上操作的帳戶鏈接是我的問題。 但是我的身份驗證 URL 可以完美運行並且能夠成功發回數據。 但是當它調用令牌 url 時,我們在這里遇到了問題。

正如我所說,我們使用 Firebase 身份驗證,我們不知道如何從 Firebase 獲取訪問令牌和刷新令牌以發送回 Google Home。

下面是我的令牌代碼,我現在只是發送常量令牌,我不知道如何獲得訪問令牌,請幫助,我真的很感謝你。

令牌 URL Firebase Function:

export const token = functions.https.onRequest(async (request, response) => {
  //admin.auth().getUser(response)
  const grantType = request.query.grant_type ?
    request.query.grant_type : request.body.grant_type;
  const secondsInDay = 86400; // 60 * 60 * 24
  const HTTP_STATUS_OK = 200;
  console.log(`Grant type ${grantType}`);


  const user = admin.auth().getUser(request.body.code);

  user.getIdToken(true).then(function(idToken) {

}).catch(function(error) {

});

  console.log(request.body.client_id);
  console.log('test');
  console.log(request.body.client_secret);


  let obj = {};
  if (grantType === 'authorization_code')  {

      obj = {
        token_type: 'bearer',
        access_token: 'jkljkhasdjhjhkdhasdsd',
        refresh_token: 'nkjcajkguiahdilawjd,bcjkbakdjhdlasd',
        expires_in: secondsInDay,
      };
  } else if (grantType === 'refresh_token') {


    obj = {
      token_type: 'bearer',
      access_token: 'njkhasiumnabkdukchaskjhkhad',
      expires_in: secondsInDay,
    };
  }
  response.status(HTTP_STATUS_OK)
    .json(obj);
});

我們使用 Firebase 身份驗證,我們不知道如何從 Firebase 獲取訪問令牌和刷新令牌以發送回 Google Home。

Firebase 身份驗證不會直接向 mint 公開功能並為用戶驗證 OAuth 令牌,它只是使您能夠提供客戶端用戶登錄和驗證。 您將需要在 Firebase 身份驗證之上實現自己的 OAuth 令牌管理。

我們有一個示例應用程序可以執行類似的操作,您可能會發現它很有幫助,還有一篇描述一些實現細節的配套博客文章 The example uses JWT to encode the Firebase Authentication user data so each request can determine how to map the Assistant intents to the Firebase uid value.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM