簡體   English   中英

從Firebase雲功能訪問Google App Engine端點

[英]Access Google App Engine endpoint from Firebase cloud function

我有一個firebase雲功能,當firebase實時數據庫發生更改時會觸發該功能。 在雲端功能中,我想點擊我的應用引擎端點。 應用引擎端點配置了“僅管理員”訪問權限的安全約束。 (請注意:端點部署在與我的Firebase雲功能項目不同的App Engine項目中。兩個項目都部署在同一個Google Cloud帳戶中)

我試圖從雲功能獲取應用程序默認憑據,並在HTTP請求中將其用於終結點,但是它正被重定向到登錄頁面。

Firebase雲功能的應用程序默認憑據的作用是什么? 是否有其他方法可以實現這一目標?

Firebase雲功能:

const gal = require('google-auth-library');

exports.makeUppercase = functions.database.ref('/{deviceId}/status')
.onWrite(event => {

      const auth = new gal.GoogleAuth();

      try {         
        auth.getApplicationDefault().then(
            function(res) {
                let client = res.credential;

                if (client.createScopedRequired && client.createScopedRequired()) {         
                    const scopes = ['https://www.googleapis.com/auth/cloud-platform'];
                    client = client.createScoped(scopes);
                }
                console.log(client);

                const url = 'https://my-secure-service-dot-my-project.appspot.com/secureEndPoint';
                client.request({url}).then(
                    function(response) { 
                        console.log(response.data);
                    }
                ).catch(err => {
                    console.error(err);
                    return err; 
                  });                       
            }
        ).catch(err => {
                    console.error(err);
                    return err; 
                  });
    } catch (e) {
        console.error(e);
    } 
});

編輯:我將端點部署在與雲功能項目相同的項目中。 端點訪問仍然失敗

編輯:下面是web.xml部分,其中為終點指定了安全約束:

  <security-constraint> <web-resource-collection> <web-resource-name>all</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> </auth-constraint> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> 

是兩個使用Identity Aware Proxy(IAP)訪問受保護的GAE端點的工作示例。 注意 :IAP將限制對整個應用程序的訪問,而不是對特定處理程序的訪問,如with login: admin

根據app.yaml關於標准 login: admin 參考 login: admin是實際用戶使用瀏覽器連接到端點的媒介。

暫無
暫無

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

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