我有一个firebase Cloud 功能,当firebase实时数据库发生变化时会触发该功能 . 在 Cloud 功能中,我想点击我的应用引擎 endpoints . 应用引擎 endpoints 配置为仅具有“admin”访问权限的安全性约束 . (注意: endpoints 部署在与我的firebase Cloud 功能项目不同的应用程序引擎项目中 . 这两个项目都部署在相同的Google Cloud 帐户中)
我试图从 Cloud 功能中获取应用程序默认凭据,并在对 endpoints 的HTTP请求中使用它,但它会重新定向到登录页面 .
firebase Cloud 功能的应用程序默认凭据的作用是什么?是否有其他方法可以实现这一目标?
Firebase Cloud 功能:
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);
}
});
编辑:我将 endpoints 部署在与 Cloud 功能项目相同的项目中 . endpoints 访问仍然失败
编辑:下面是web.xml部分,其中为 endpoints 指定了安全性约束:
<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>
1 回答
Here是使用Identity Aware Proxy(IAP)访问受保护的GAE endpoints 的两个工作示例 . Notice :IAP将限制对整个应用程序的访问,而不是对
with login: admin
的特定处理程序的访问 .根据app.yaml reference for standard
login: admin
是真实用户使用浏览器连接到 endpoints 的媒介 .