reactjs - Firebase:如何手动将 Google 登录身份验证器限制为特定的电子邮件地址?
问题描述
我如何才能将我的 React.js Web 应用程序上的 Google 登录仅用于特定的电子邮件地址?
我不希望限制某个域,而是告诉身份验证器只有特定的电子邮件地址可以注册或登录,并为所有其他人抛出错误。
谢谢。
解决方案
Firebase 身份验证中没有内置任何内容来限制登录到特定域或电子邮件地址。但是,如果您升级到 Google Cloud Identity(付费升级),您可以使用阻止的 Cloud Function 自定义身份验证流程。
基于该链接中的示例:
// Import the Cloud Auth Admin module.
const gcipCloudFunctions = require('gcip-cloud-functions');
// Initialize the Auth client.
const authClient = new gcipCloudFunctions.Auth();
// Http trigger with Cloud Functions.
exports.beforeCreate = authClient.functions().beforeCreateHandler((user, context) => {
// If the user is authenticating within a tenant context, the tenant ID can be determined from
// user.tenantId or from context.resource, eg. 'projects/project-id/tenant/tenant-id-1'
// Only this one user can sign up.
if (user.email !== 'user@acme.com') {
throw new gcipCloudFunctions.https.HttpsError('invalid-argument', `Unauthorized email "${user.email}"`);
});
推荐阅读
- android - MediaStore DATE_TAKEN 的替代解决方案
- flutter - Flutter:从下一页返回运行功能后刷新页面
- java - 信号量问题:从并行线程访问线程变量
- python - gcc 找不到 Python.h
- python - Django:将外部 API 响应映射并存储到具有多对多关系的复杂模型中
- javascript - 大多数组件的 react-dates 库的渲染问题
- mule - 如何检查有效载荷大小
- javascript - 如何检测/避免对我缓存的基于 React 的应用程序的更新?或者如何在缓存失效发生之前检测到它?
- authentication - Schoology API OAuth 1.0 在调用 auth/authorize 端点时抛出 404 错误
- pandas - 如何在熊猫中对多列执行半连接?