繁体   English   中英

Android 应用程序的 Firebase Cloud Functions 身份验证

[英]Firebase Cloud Functions authentication for Android App

我正在构建一个搜索附近位置的 Android 应用程序。 I use Firebase login system (Login with email and password, and login with Google, Facebook, etc), therefore I would also like to build an API with Firebase. (也是因为我需要更复杂的应用程序)我已经使用 Firebase Cloud Functions 构建了一个无服务器 API,并且我可以使用 Postman 发出 GET/PUT 请求。 但是,我想保护这些端点,类似于 JWT 如何保护 RESTAPI,以便只有登录应用程序的用户才能发出请求。 我如何实现这一目标? 我看过“authorized-https-endpoint”,但它似乎只允许谷歌登录。

或者有没有办法让我仍然可以使用 Node 和 Mongodb RestAPI,并使用登录到 Firebase 的帐户来保护它?

这是一段后端代码

app.get('/api/read/:item_id', (req, res) => {
(async () => {
    try {
        const document = db.collection('items').doc(req.params.item_id);
        let item = await document.get();
        let response = item.data();
        return res.status(200).send(response);
    } catch (error) {
        console.log(error);
        return res.status(500).send(error);
    }
    })();
});


exports.app = functions.https.onRequest(app);

非常感谢你们。

使用 Firebase 可调用函数。 它们满足您的要求。

参考: https://firebase.google.com/docs/functions/callable

如果 function 调用存在问题,请参阅:firebase.google.com/docs/functions/callable-reference。
正如这里提到的,这仅在 SDK 不适合您时使用

授权的https-endpoint示例支持客户端上的所有forms auth,只要它通过Firebase Auth SDK。 In all cases, the client can send an auth token to the function, and the function code can use the Firebase Admin SDK to verify the token . 用户的身份验证方式无关紧要 - 任何 Firebase 用户帐户都可以使用。

您还可以使用可调用的 function ,它将以完全相同的方式自动为您执行验证。 然后,您的代码必须在继续之前检查用户是否使用调用上下文进行了身份验证。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM