从零开始搭建安全的学校网站认证系统

张开发
2026/4/10 21:15:11 15 分钟阅读

分享文章

从零开始搭建安全的学校网站认证系统
引言在构建一个面向学校的网站时,用户认证是一个不可忽视的环节。本文将结合实例,详细讲解如何通过Firebase Authentication和Google OAuth 2.0实现一个安全的用户登录系统,并解决常见的错误及后续开发步骤。背景假设我们已经有了一个简单的学校网站,但现在需要增强其安全性,特别是在用户认证方面。原有的系统使用了Google登录,但遇到了令牌验证问题。问题分析用户在访问/login路由时,会被重定向到Google登录页面,登录后返回到/app路由。然而,控制台报错显示Firebase ID令牌的aud(audience)声明不正确。错误信息FirebaseAuthError: Firebase ID token has incorrect "aud" (audience) claim. Expected "school-progress-g" but got "1090170234957-5ntr48jf178o9befpp5n0603hoh7m2rh.apps.googleusercontent.com". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK

更多文章