63 lines
1.9 KiB
Markdown
63 lines
1.9 KiB
Markdown
当前项目架构分析
|
||
|
||
现有认证系统:
|
||
- 基于适配器模式的多平台用户认证系统
|
||
- 支持微信、字节跳动等小程序平台登录
|
||
- 统一用户实体(UserEntity)和平台用户实体(PlatformUserEntity)
|
||
- 无Passport.js依赖,采用自定义适配器架构
|
||
|
||
缺失依赖:
|
||
- 项目未安装@nestjs/passport和passport-google-oauth20
|
||
- 需要安装Google OAuth相关依赖
|
||
|
||
Google登录集成实施方案
|
||
|
||
第一阶段:依赖安装
|
||
|
||
1. 安装必要依赖包
|
||
pnpm add @nestjs/passport passport passport-google-oauth20 @types/passport-google-oauth20
|
||
|
||
第二阶段:平台类型扩展
|
||
|
||
2. 更新PlatformType枚举 (src/entities/platform-user.entity.ts:29)
|
||
- 添加GOOGLE = 'google'选项
|
||
|
||
第三阶段:Google OAuth适配器实现
|
||
|
||
3. 创建Google适配器 (src/platform/adapters/google.adapter.ts)
|
||
- 继承BaseAdapter基类
|
||
- 实现Google OAuth 2.0认证流程
|
||
- 支持访问令牌和刷新令牌管理
|
||
4. 创建Google Strategy (src/auth/strategies/google.strategy.ts)
|
||
- 实现Passport Google OAuth2.0策略
|
||
- 与适配器系统集成
|
||
|
||
第四阶段:认证模块构建
|
||
|
||
5. 创建Auth模块 (src/auth/)
|
||
- auth.module.ts: 配置Passport和Google Strategy
|
||
- auth.controller.ts: Google OAuth路由端点
|
||
- auth.guard.ts: Google认证守卫
|
||
|
||
第五阶段:系统集成
|
||
|
||
6. 更新PlatformModule (src/platform/platform.module.ts:66)
|
||
- 注册GoogleAdapter到适配器工厂
|
||
7. 更新AppModule (src/app.module.ts:58)
|
||
- 导入新建的AuthModule
|
||
|
||
第六阶段:环境配置
|
||
|
||
8. 配置环境变量
|
||
- GOOGLE_CLIENT_ID: Google OAuth客户端ID
|
||
- GOOGLE_CLIENT_SECRET: Google OAuth客户端密钥
|
||
- GOOGLE_CALLBACK_URL: OAuth回调URL
|
||
|
||
第七阶段:API端点
|
||
|
||
9. 实现Google登录端点
|
||
- GET /auth/google: 启动Google OAuth流程
|
||
- GET /auth/google/callback: 处理OAuth回调
|
||
- POST /auth/google/token: 处理移动端token交换
|
||
|
||
这个方案将Google登录无缝集成到现有的多平台认证架构中,保持系统的一致性和可扩展性。 |