ruoyi-vue-pro 开发指南 ruoyi-vue-pro 开发指南
  • 萌新必读
  • 后端手册
  • 中间件手册
  • 工作流手册
  • 大屏手册
  • 支付手册
  • 商城手册
  • 公众号手册
  • 系统手册
  • 运维手册
  • 前端手册 Vue 2.x
  • 前端手册 Vue 3.x
  • 工作流手册
  • 大屏手册
  • 支付手册
  • 商城手册
  • 公众号手册
  • 系统手册
视频教程
  • Vue3 + element-plus (opens new window)
  • Vue3 + vben(ant-design-vue) (opens new window)
  • Vue2 + element-ui (opens new window)
微服务版 (opens new window)
作者博客 (opens new window)
GitHub (opens new window)
  • 萌新必读
  • 后端手册
  • 中间件手册
  • 工作流手册
  • 大屏手册
  • 支付手册
  • 商城手册
  • 公众号手册
  • 系统手册
  • 运维手册
  • 前端手册 Vue 2.x
  • 前端手册 Vue 3.x
  • 工作流手册
  • 大屏手册
  • 支付手册
  • 商城手册
  • 公众号手册
  • 系统手册
视频教程
  • Vue3 + element-plus (opens new window)
  • Vue3 + vben(ant-design-vue) (opens new window)
  • Vue2 + element-ui (opens new window)
微服务版 (opens new window)
作者博客 (opens new window)
GitHub (opens new window)
  • 萌新必读

    • 简介
    • 交流群
    • 视频教程
    • 功能列表
    • 快速启动(适合“后端”工程师)
    • 快速启动(适合“前端”工程师)
    • 接口文档
    • 技术选型
    • 项目结构
    • 代码热加载
    • 一键改包
    • 删除功能
    • 内网穿透
  • 后端手册

    • 新建模块
    • 代码生成(新增功能)
    • 功能权限
    • 数据权限
    • 用户体系
    • 三方登录
      • 1. 表结构
      • 2. 绑定登录
      • 3. 快捷登录
      • 4. 绑定与解绑
      • 5. 配置文件
      • 6. 第三方平台的申请
    • OAuth 2.0(SSO 单点登录)
    • SaaS 多租户【字段隔离】
    • SaaS 多租户【数据库隔离】
    • 异常处理(错误码)
    • 参数校验
    • 分页实现
    • 文件存储(上传下载)
    • Excel 导入导出
    • 系统日志
    • MyBatis 数据库
    • MyBatis 联表&分页查询
    • 多数据源(读写分离)
    • Redis 缓存
    • 本地缓存
    • 异步任务
    • 配置管理
    • 工具类 Util
    • 单元测试
    • 分布式锁
    • 幂等性(防重复提交)
    • 数据库文档
    • 验证码
  • 中间件手册

    • 消息队列
    • 定时任务
    • 限流熔断
  • 工作流手册

    • 工作流(Flowable)会签、或签
  • 商城手册

    • 商城演示
    • 功能开启
  • 大屏手册

    • 报表设计器
    • 大屏设计器
  • 支付手册

    • 功能开启
    • 支付宝支付接入
    • 微信公众号支付接入
    • 微信小程序支付接入
    • 支付宝、微信退款接入
  • 公众号手册

    • 功能开启
    • 公众号接入
    • 公众号粉丝
    • 公众号标签
    • 公众号消息
    • 自动回复
    • 公众号菜单
    • 公众号素材
    • 公众号图文
    • 公众号统计
  • 系统手册

    • 短信配置
    • 邮件配置
    • 站内信配置
    • 数据脱敏
    • 敏感词
    • 地区 & IP 库
  • 运维手册

    • 开发环境
    • Linux 部署
    • Docker 部署
    • Jenkins 部署
    • HTTPS 证书
    • 服务监控
  • 前端手册 Vue 2

    • 开发规范
    • 菜单路由
    • Icon 图标
    • 字典数据
    • 系统组件
    • 通用方法
    • 配置读取
  • 前端手册 Vue 3

    • 开发规范
    • 菜单路由
    • Icon 图标
    • 字典数据
    • 系统组件
    • 通用方法
    • 配置读取
    • CRUD 组件
    • 国际化
    • IDE 调试
  • 更新日志

    • 【v1.8.2】2023-09-24
    • 【v1.8.1】2023-09-04
    • 【v1.8.0】2023-07-27
    • 【v1.7.3】2023-05-29
    • 【v1.7.2】2023-04-19
  • 开发指南
  • 后端手册
芋道源码
2022-03-28
目录

三方登录

系统对接国内多个第三方平台,实现三方登录的功能。例如说:

  • 管理后台:企业微信、阿里钉钉
  • 用户 App:微信公众号、微信小程序

管理后台

友情提示:为了表述方便,本文主要使用管理后台的三方登录作为示例。

用户 App 也是支持该功能,你可以自己去体验一下。

# 1. 表结构

① 三方登录完成时,系统会将三方用户存储到 system_social_user (opens new window) 表中,通过 type (opens new window) 标记对应的第三方平台。

② 【未】关联本系统 User 的三方用户,需要在三方登录完成后,使用账号密码进行「绑定登录」,成功后记录到 system_social_user_bind (opens new window) 表中。

【已】关联本系统 User 的三方用户,在三方登录完成后,直接进入系统,即「快捷登录」。

# 2. 绑定登录

① 使用浏览器访问 http://127.0.0.1:1024/login (opens new window) 地址,点击 [钉钉] 或者 [企业微信] 进行三方登录。此时,会调用 /admin-api/system/auth/social-auth-redirect (opens new window) 接口,获得第三方平台的登录地址,并进行跳转。

三方登录

然后,使用 [钉钉] 或者 [企业微信] 进行扫码,完成三方登录。

② 三方登录成功后,跳转回 http://127.0.0.1:1024/social-login (opens new window) 地址。此时,会调用 /admin-api/system/auth/social-login (opens new window) 接口,尝试「快捷登录」。由于该三方用户【未】关联管理后台的 AdminUser 用户,所以会看到 “未绑定账号,需要进行绑定” 报错。

三方登录页

③ 输入账号密码,点击 [提交] 按钮,进行「绑定登录」。此时,会调用 /admin-api/system/auth/login (opens new window) 接口(在账号密码登录的基础上,额外带上 socialType + socialCode + socialState 参数)。成功后,即可进入系统的首页。

三方登录页

# 3. 快捷登录

退出系统,再进行一次三方登录的流程。

【相同】① 使用浏览器访问 http://127.0.0.1:1024/login (opens new window) 地址,点击 [钉钉] 或者 [企业微信] 进行三方登录。此时,会调用 /admin-api/system/auth/social-auth-redirect (opens new window) 接口,获得第三方平台的登录地址,并进行跳转。

三方登录

【不同】② 三方登录成功后,跳转回 http://127.0.0.1:1024/social-login (opens new window) 地址。此时,会调用 /admin-api/system/auth/social-login (opens new window) 接口,尝试「快捷登录」。由于该三方用户【已】关联管理后台的 AdminUser 用户,所以直接进入系统的首页。

三方登录页

# 4. 绑定与解绑

访问 http://127.0.0.1:1024/user/profile (opens new window) 地址,选择 [社交信息] 选项,可以三方用户的绑定与解绑。

绑定与解绑

# 5. 配置文件

在 application-{env}.yaml (opens new window) 配置文件中,对应 justauth 配置项,填写你的第三方平台的配置信息。

配置文件

系统使用 justauth-spring-boot-starter (opens new window) JustAuth (opens new window) 组件,想要对接其它第三方平台,只需要新增对应的配置信息即可。

疑问:yudao-spring-boot-starter-biz-social 技术组件的作用是什么?

yudao-spring-boot-starter-biz-social (opens new window) 对 JustAuth 进行二次封装,提供微信小程序的集成。

# 6. 第三方平台的申请

  • 阿里钉钉:https://justauth.wiki/guide/oauth/dingtalk/ (opens new window)
  • 企业微信:https://justauth.wiki/guide/oauth/wechat_enterprise_qrcode/ (opens new window)
  • 微信开放平台:https://justauth.wiki/guide/oauth/wechat_open/ (opens new window)

注意,如果第三方平台如果需要配置具体的授信地址,需要添加 /social-login 用于三方登录回调页、/user/profile 用于三方用户的绑定与解绑。

上次更新: 2022/07/06, 00:54:39
用户体系
OAuth 2.0(SSO 单点登录)

← 用户体系 OAuth 2.0(SSO 单点登录)→

Theme by Vdoing | Copyright © 2019-2023 芋道源码 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×