ai-engineering-init 1.3.4 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/hooks/skill-forced-eval.js +2 -0
- package/.claude/settings.json +3 -3
- package/.claude/skills/add-skill/SKILL.md +79 -32
- package/.claude/skills/api-development/SKILL.md +83 -377
- package/.claude/skills/architecture-design/SKILL.md +138 -632
- package/.claude/skills/backend-annotations/SKILL.md +134 -506
- package/.claude/skills/banana-image/SKILL.md +10 -3
- package/.claude/skills/brainstorm/SKILL.md +103 -535
- package/.claude/skills/bug-detective/SKILL.md +147 -1097
- package/.claude/skills/bug-detective/references/error-patterns.md +242 -0
- package/.claude/skills/code-patterns/SKILL.md +116 -426
- package/.claude/skills/code-patterns/references/leniu-code-patterns.md +87 -0
- package/.claude/skills/crud-development/SKILL.md +64 -304
- package/.claude/skills/data-permission/SKILL.md +105 -412
- package/.claude/skills/data-permission/references/custom-data-scope.md +90 -0
- package/.claude/skills/file-oss-management/SKILL.md +106 -714
- package/.claude/skills/file-oss-management/references/entities.md +105 -0
- package/.claude/skills/file-oss-management/references/service-impl.md +104 -0
- package/.claude/skills/leniu-api-development/SKILL.md +142 -626
- package/.claude/skills/leniu-api-development/references/real-examples.md +273 -0
- package/.claude/skills/leniu-architecture-design/SKILL.md +176 -391
- package/.claude/skills/leniu-backend-annotations/SKILL.md +132 -519
- package/.claude/skills/leniu-brainstorm/SKILL.md +132 -541
- package/.claude/skills/leniu-brainstorm/references/business-scenarios.md +162 -0
- package/.claude/skills/leniu-crud-development/SKILL.md +232 -938
- package/.claude/skills/leniu-crud-development/references/templates.md +597 -0
- package/.claude/skills/leniu-customization-location/SKILL.md +410 -0
- package/.claude/skills/leniu-data-permission/SKILL.md +70 -0
- package/.claude/skills/leniu-java-entity/SKILL.md +76 -590
- package/.claude/skills/leniu-java-entity/references/templates.md +237 -0
- package/.claude/skills/leniu-java-export/SKILL.md +94 -379
- package/.claude/skills/leniu-java-logging/SKILL.md +106 -709
- package/.claude/skills/leniu-java-logging/references/data-mask.md +46 -0
- package/.claude/skills/leniu-java-logging/references/logging-scenarios.md +113 -0
- package/.claude/skills/leniu-java-mybatis/SKILL.md +73 -446
- package/.claude/skills/leniu-java-mybatis/references/report-mapper.md +88 -0
- package/.claude/skills/leniu-report-customization/SKILL.md +111 -365
- package/.claude/skills/leniu-report-customization/references/table-fields.md +93 -0
- package/.claude/skills/leniu-report-standard-customization/SKILL.md +111 -334
- package/.claude/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
- package/.claude/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
- package/.claude/skills/leniu-security-guard/SKILL.md +133 -347
- package/.claude/skills/mysql-debug/SKILL.md +364 -0
- package/.claude/skills/openspec-apply-change/SKILL.md +10 -1
- package/.claude/skills/openspec-archive-change/SKILL.md +9 -1
- package/.claude/skills/openspec-bulk-archive-change/SKILL.md +9 -1
- package/.claude/skills/openspec-continue-change/SKILL.md +9 -1
- package/.claude/skills/openspec-explore/SKILL.md +10 -1
- package/.claude/skills/openspec-ff-change/SKILL.md +9 -1
- package/.claude/skills/openspec-new-change/SKILL.md +9 -1
- package/.claude/skills/openspec-onboard/SKILL.md +15 -130
- package/.claude/skills/openspec-sync-specs/SKILL.md +9 -1
- package/.claude/skills/openspec-verify-change/SKILL.md +9 -1
- package/.claude/skills/performance-doctor/SKILL.md +110 -434
- package/.claude/skills/redis-cache/SKILL.md +89 -595
- package/.claude/skills/redis-cache/references/listeners.md +23 -0
- package/.claude/skills/scheduled-jobs/SKILL.md +88 -407
- package/.claude/skills/security-guard/SKILL.md +137 -532
- package/.claude/skills/security-guard/references/encrypt-config.md +103 -0
- package/.claude/skills/security-guard/references/sensitive-strategies.md +42 -0
- package/.claude/skills/sms-mail/SKILL.md +116 -574
- package/.claude/skills/sms-mail/references/mail-config.md +88 -0
- package/.claude/skills/sms-mail/references/sms-config.md +74 -0
- package/.claude/skills/social-login/SKILL.md +112 -514
- package/.claude/skills/social-login/references/provider-configs.md +118 -0
- package/.claude/skills/tenant-management/SKILL.md +129 -444
- package/.claude/skills/tenant-management/references/tenant-scenarios.md +91 -0
- package/.claude/skills/test-development/SKILL.md +86 -540
- package/.claude/skills/test-development/references/parameterized-examples.md +119 -0
- package/.claude/skills/utils-toolkit/SKILL.md +52 -305
- package/.claude/skills/utils-toolkit/references/redis-utils-api.md +56 -0
- package/.claude/skills/websocket-sse/SKILL.md +105 -550
- package/.claude/skills/workflow-engine/SKILL.md +147 -502
- package/.codex/skills/add-skill/SKILL.md +79 -32
- package/.codex/skills/api-development/SKILL.md +172 -599
- package/.codex/skills/architecture-design/SKILL.md +138 -504
- package/.codex/skills/backend-annotations/SKILL.md +134 -496
- package/.codex/skills/banana-image/SKILL.md +10 -3
- package/.codex/skills/brainstorm/SKILL.md +103 -535
- package/.codex/skills/bug-detective/SKILL.md +147 -1097
- package/.codex/skills/bug-detective/references/error-patterns.md +242 -0
- package/.codex/skills/code-patterns/SKILL.md +120 -282
- package/.codex/skills/code-patterns/references/leniu-code-patterns.md +87 -0
- package/.codex/skills/crud-development/SKILL.md +64 -292
- package/.codex/skills/data-permission/SKILL.md +108 -407
- package/.codex/skills/data-permission/references/custom-data-scope.md +90 -0
- package/.codex/skills/database-ops/SKILL.md +8 -154
- package/.codex/skills/error-handler/SKILL.md +10 -0
- package/.codex/skills/file-oss-management/SKILL.md +106 -714
- package/.codex/skills/file-oss-management/references/entities.md +105 -0
- package/.codex/skills/file-oss-management/references/service-impl.md +104 -0
- package/.codex/skills/git-workflow/SKILL.md +27 -5
- package/.codex/skills/leniu-api-development/SKILL.md +142 -626
- package/.codex/skills/leniu-api-development/references/real-examples.md +273 -0
- package/.codex/skills/leniu-architecture-design/SKILL.md +176 -391
- package/.codex/skills/leniu-backend-annotations/SKILL.md +132 -519
- package/.codex/skills/leniu-brainstorm/SKILL.md +132 -541
- package/.codex/skills/leniu-brainstorm/references/business-scenarios.md +162 -0
- package/.codex/skills/leniu-crud-development/SKILL.md +232 -938
- package/.codex/skills/leniu-crud-development/references/templates.md +597 -0
- package/.codex/skills/leniu-customization-location/SKILL.md +410 -0
- package/.codex/skills/leniu-data-permission/SKILL.md +70 -0
- package/.codex/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.codex/skills/leniu-java-entity/SKILL.md +76 -590
- package/.codex/skills/leniu-java-entity/references/templates.md +237 -0
- package/.codex/skills/leniu-java-export/SKILL.md +94 -379
- package/.codex/skills/leniu-java-logging/SKILL.md +106 -709
- package/.codex/skills/leniu-java-logging/references/data-mask.md +46 -0
- package/.codex/skills/leniu-java-logging/references/logging-scenarios.md +113 -0
- package/.codex/skills/leniu-java-mybatis/SKILL.md +73 -446
- package/.codex/skills/leniu-java-mybatis/references/report-mapper.md +88 -0
- package/.codex/skills/leniu-report-customization/SKILL.md +111 -365
- package/.codex/skills/leniu-report-customization/references/table-fields.md +93 -0
- package/.codex/skills/leniu-report-standard-customization/SKILL.md +111 -334
- package/.codex/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
- package/.codex/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
- package/.codex/skills/leniu-security-guard/SKILL.md +133 -347
- package/.codex/skills/mysql-debug/SKILL.md +364 -0
- package/.codex/skills/openspec-apply-change/SKILL.md +10 -1
- package/.codex/skills/openspec-archive-change/SKILL.md +9 -1
- package/.codex/skills/openspec-bulk-archive-change/SKILL.md +9 -1
- package/.codex/skills/openspec-continue-change/SKILL.md +9 -1
- package/.codex/skills/openspec-explore/SKILL.md +10 -1
- package/.codex/skills/openspec-ff-change/SKILL.md +9 -1
- package/.codex/skills/openspec-new-change/SKILL.md +9 -1
- package/.codex/skills/openspec-onboard/SKILL.md +15 -130
- package/.codex/skills/openspec-sync-specs/SKILL.md +9 -1
- package/.codex/skills/openspec-verify-change/SKILL.md +9 -1
- package/.codex/skills/performance-doctor/SKILL.md +110 -434
- package/.codex/skills/project-navigator/SKILL.md +20 -1
- package/.codex/skills/redis-cache/SKILL.md +93 -589
- package/.codex/skills/redis-cache/references/listeners.md +23 -0
- package/.codex/skills/scheduled-jobs/SKILL.md +88 -407
- package/.codex/skills/security-guard/SKILL.md +141 -527
- package/.codex/skills/security-guard/references/encrypt-config.md +103 -0
- package/.codex/skills/security-guard/references/sensitive-strategies.md +42 -0
- package/.codex/skills/sms-mail/SKILL.md +116 -574
- package/.codex/skills/sms-mail/references/mail-config.md +88 -0
- package/.codex/skills/sms-mail/references/sms-config.md +74 -0
- package/.codex/skills/social-login/SKILL.md +112 -514
- package/.codex/skills/social-login/references/provider-configs.md +118 -0
- package/.codex/skills/store-pc/SKILL.md +258 -383
- package/.codex/skills/tenant-management/SKILL.md +129 -444
- package/.codex/skills/tenant-management/references/tenant-scenarios.md +91 -0
- package/.codex/skills/test-development/SKILL.md +86 -540
- package/.codex/skills/test-development/references/parameterized-examples.md +119 -0
- package/.codex/skills/ui-pc/SKILL.md +350 -387
- package/.codex/skills/utils-toolkit/SKILL.md +52 -283
- package/.codex/skills/utils-toolkit/references/redis-utils-api.md +56 -0
- package/.codex/skills/websocket-sse/SKILL.md +105 -550
- package/.codex/skills/workflow-engine/SKILL.md +147 -502
- package/.cursor/hooks/cursor-skill-eval.js +53 -1
- package/.cursor/hooks.json +3 -3
- package/.cursor/skills/add-skill/SKILL.md +79 -32
- package/.cursor/skills/api-development/SKILL.md +83 -377
- package/.cursor/skills/architecture-design/SKILL.md +138 -632
- package/.cursor/skills/backend-annotations/SKILL.md +134 -506
- package/.cursor/skills/banana-image/SKILL.md +10 -3
- package/.cursor/skills/brainstorm/SKILL.md +103 -535
- package/.cursor/skills/bug-detective/SKILL.md +147 -1097
- package/.cursor/skills/bug-detective/references/error-patterns.md +242 -0
- package/.cursor/skills/code-patterns/SKILL.md +116 -426
- package/.cursor/skills/code-patterns/references/leniu-code-patterns.md +87 -0
- package/.cursor/skills/crud-development/SKILL.md +64 -304
- package/.cursor/skills/data-permission/SKILL.md +105 -412
- package/.cursor/skills/data-permission/references/custom-data-scope.md +90 -0
- package/.cursor/skills/file-oss-management/SKILL.md +106 -714
- package/.cursor/skills/file-oss-management/references/entities.md +105 -0
- package/.cursor/skills/file-oss-management/references/service-impl.md +104 -0
- package/.cursor/skills/git-workflow/SKILL.md +27 -5
- package/.cursor/skills/leniu-api-development/SKILL.md +142 -626
- package/.cursor/skills/leniu-api-development/references/real-examples.md +273 -0
- package/.cursor/skills/leniu-architecture-design/SKILL.md +176 -391
- package/.cursor/skills/leniu-backend-annotations/SKILL.md +132 -519
- package/.cursor/skills/leniu-brainstorm/SKILL.md +132 -541
- package/.cursor/skills/leniu-brainstorm/references/business-scenarios.md +162 -0
- package/.cursor/skills/leniu-crud-development/SKILL.md +232 -938
- package/.cursor/skills/leniu-crud-development/references/templates.md +597 -0
- package/.cursor/skills/leniu-customization-location/SKILL.md +410 -0
- package/.cursor/skills/leniu-data-permission/SKILL.md +70 -0
- package/.cursor/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.cursor/skills/leniu-java-entity/SKILL.md +76 -590
- package/.cursor/skills/leniu-java-entity/references/templates.md +237 -0
- package/.cursor/skills/leniu-java-export/SKILL.md +94 -379
- package/.cursor/skills/leniu-java-logging/SKILL.md +106 -709
- package/.cursor/skills/leniu-java-logging/references/data-mask.md +46 -0
- package/.cursor/skills/leniu-java-logging/references/logging-scenarios.md +113 -0
- package/.cursor/skills/leniu-java-mybatis/SKILL.md +73 -446
- package/.cursor/skills/leniu-java-mybatis/references/report-mapper.md +88 -0
- package/.cursor/skills/leniu-report-customization/SKILL.md +111 -365
- package/.cursor/skills/leniu-report-customization/references/table-fields.md +93 -0
- package/.cursor/skills/leniu-report-standard-customization/SKILL.md +111 -334
- package/.cursor/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
- package/.cursor/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
- package/.cursor/skills/leniu-security-guard/SKILL.md +133 -347
- package/.cursor/skills/mysql-debug/SKILL.md +364 -0
- package/.cursor/skills/openspec-apply-change/SKILL.md +10 -1
- package/.cursor/skills/openspec-archive-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-bulk-archive-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-continue-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-explore/SKILL.md +10 -1
- package/.cursor/skills/openspec-ff-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-new-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-onboard/SKILL.md +15 -130
- package/.cursor/skills/openspec-sync-specs/SKILL.md +9 -1
- package/.cursor/skills/openspec-verify-change/SKILL.md +9 -1
- package/.cursor/skills/performance-doctor/SKILL.md +110 -434
- package/.cursor/skills/redis-cache/SKILL.md +89 -595
- package/.cursor/skills/redis-cache/references/listeners.md +23 -0
- package/.cursor/skills/scheduled-jobs/SKILL.md +88 -407
- package/.cursor/skills/security-guard/SKILL.md +137 -532
- package/.cursor/skills/security-guard/references/encrypt-config.md +103 -0
- package/.cursor/skills/security-guard/references/sensitive-strategies.md +42 -0
- package/.cursor/skills/sms-mail/SKILL.md +116 -574
- package/.cursor/skills/sms-mail/references/mail-config.md +88 -0
- package/.cursor/skills/sms-mail/references/sms-config.md +74 -0
- package/.cursor/skills/social-login/SKILL.md +112 -514
- package/.cursor/skills/social-login/references/provider-configs.md +118 -0
- package/.cursor/skills/tenant-management/SKILL.md +129 -444
- package/.cursor/skills/tenant-management/references/tenant-scenarios.md +91 -0
- package/.cursor/skills/test-development/SKILL.md +86 -540
- package/.cursor/skills/test-development/references/parameterized-examples.md +119 -0
- package/.cursor/skills/utils-toolkit/SKILL.md +52 -305
- package/.cursor/skills/utils-toolkit/references/redis-utils-api.md +56 -0
- package/.cursor/skills/websocket-sse/SKILL.md +105 -550
- package/.cursor/skills/workflow-engine/SKILL.md +147 -502
- package/package.json +1 -1
|
@@ -16,277 +16,108 @@ description: |
|
|
|
16
16
|
# 第三方登录开发指南(JustAuth)
|
|
17
17
|
|
|
18
18
|
> **适用模块**:`ruoyi-common-social`(基于 JustAuth)
|
|
19
|
+
> **特性**:Sa-Token 认证集成、Redis 状态缓存(防 CSRF)、多租户支持、账号绑定机制
|
|
19
20
|
|
|
20
|
-
##
|
|
21
|
+
## 一、支持平台
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
| 平台 | source 标识 | 平台 | source 标识 |
|
|
24
|
+
|------|------------|------|------------|
|
|
25
|
+
| 钉钉 | `dingtalk` | GitHub | `github` |
|
|
26
|
+
| Gitee | `gitee` | 微博 | `weibo` |
|
|
27
|
+
| 支付宝 | `alipay_wallet` | QQ | `qq` |
|
|
28
|
+
| 微信开放平台 | `wechat_open` | 微信公众号 | `wechat_mp` |
|
|
29
|
+
| 企业微信 | `wechat_enterprise` | 抖音 | `douyin` |
|
|
30
|
+
| 华为 | `huawei` | 微软 | `microsoft` |
|
|
31
|
+
| MaxKey | `maxkey` | TopIAM | `topiam` |
|
|
32
|
+
| GitLab | `gitlab` | Gitea | `gitea` |
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
- ✅ 开箱即用,配置即生效
|
|
26
|
-
- ✅ 支持 20+ 社交平台
|
|
27
|
-
- ✅ Redis 状态缓存(防 CSRF)
|
|
28
|
-
- ✅ 多租户支持
|
|
29
|
-
- ✅ 账号绑定机制
|
|
34
|
+
完整平台列表及特殊配置详见 `references/provider-configs.md`。
|
|
30
35
|
|
|
31
36
|
---
|
|
32
37
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
### 1.1 已集成平台列表
|
|
36
|
-
|
|
37
|
-
| 平台 | source 标识 | 说明 |
|
|
38
|
-
|------|------------|------|
|
|
39
|
-
| 钉钉 | `dingtalk` | 钉钉扫码登录(V2) |
|
|
40
|
-
| 百度 | `baidu` | 百度账号登录 |
|
|
41
|
-
| GitHub | `github` | GitHub OAuth |
|
|
42
|
-
| Gitee | `gitee` | 码云账号登录 |
|
|
43
|
-
| 微博 | `weibo` | 新浪微博登录 |
|
|
44
|
-
| Coding | `coding` | Coding 账号登录 |
|
|
45
|
-
| 开源中国 | `oschina` | OSChina 账号登录 |
|
|
46
|
-
| 支付宝 | `alipay_wallet` | 支付宝钱包登录 |
|
|
47
|
-
| QQ | `qq` | QQ 互联登录 |
|
|
48
|
-
| 微信开放平台 | `wechat_open` | 微信扫码登录 |
|
|
49
|
-
| 微信公众号 | `wechat_mp` | 微信公众号授权 |
|
|
50
|
-
| 企业微信 | `wechat_enterprise` | 企业微信扫码登录 |
|
|
51
|
-
| 淘宝 | `taobao` | 淘宝账号登录 |
|
|
52
|
-
| 抖音 | `douyin` | 抖音账号登录 |
|
|
53
|
-
| LinkedIn | `linkedin` | 领英账号登录 |
|
|
54
|
-
| Microsoft | `microsoft` | 微软账号登录 |
|
|
55
|
-
| 人人网 | `renren` | 人人网账号登录 |
|
|
56
|
-
| StackOverflow | `stack_overflow` | StackOverflow 登录 |
|
|
57
|
-
| 华为 | `huawei` | 华为账号登录(V3) |
|
|
58
|
-
| GitLab | `gitlab` | GitLab 账号登录 |
|
|
59
|
-
| 阿里云 | `aliyun` | 阿里云账号登录 |
|
|
60
|
-
| MaxKey | `maxkey` | MaxKey 单点登录 |
|
|
61
|
-
| TopIAM | `topiam` | TopIAM 单点登录 |
|
|
62
|
-
| Gitea | `gitea` | Gitea 账号登录 |
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
## 二、配置第三方登录
|
|
67
|
-
|
|
68
|
-
### 2.1 基础配置
|
|
38
|
+
## 二、基础配置
|
|
69
39
|
|
|
70
40
|
```yaml
|
|
71
|
-
# application.yml
|
|
72
41
|
justauth:
|
|
42
|
+
address: https://your-domain.com # 回调地址前缀
|
|
73
43
|
type:
|
|
74
|
-
# GitHub 登录配置
|
|
75
44
|
github:
|
|
76
|
-
client-id: ${GITHUB_CLIENT_ID}
|
|
77
|
-
client-secret: ${GITHUB_CLIENT_SECRET}
|
|
78
|
-
redirect-uri: ${
|
|
79
|
-
|
|
80
|
-
# Gitee 登录配置
|
|
45
|
+
client-id: ${GITHUB_CLIENT_ID:}
|
|
46
|
+
client-secret: ${GITHUB_CLIENT_SECRET:}
|
|
47
|
+
redirect-uri: ${justauth.address}/social-callback?source=github
|
|
81
48
|
gitee:
|
|
82
|
-
client-id: ${GITEE_CLIENT_ID}
|
|
83
|
-
client-secret: ${GITEE_CLIENT_SECRET}
|
|
84
|
-
redirect-uri: ${
|
|
85
|
-
|
|
86
|
-
# 钉钉登录配置
|
|
49
|
+
client-id: ${GITEE_CLIENT_ID:}
|
|
50
|
+
client-secret: ${GITEE_CLIENT_SECRET:}
|
|
51
|
+
redirect-uri: ${justauth.address}/social-callback?source=gitee
|
|
87
52
|
dingtalk:
|
|
88
|
-
client-id: ${DINGTALK_APP_KEY}
|
|
89
|
-
client-secret: ${DINGTALK_APP_SECRET}
|
|
90
|
-
redirect-uri: ${
|
|
91
|
-
|
|
92
|
-
# 微信开放平台配置
|
|
93
|
-
wechat_open:
|
|
94
|
-
client-id: ${WECHAT_APP_ID}
|
|
95
|
-
client-secret: ${WECHAT_APP_SECRET}
|
|
96
|
-
redirect-uri: ${server.url}/social-callback?source=wechat_open
|
|
97
|
-
|
|
98
|
-
# QQ 登录配置
|
|
99
|
-
qq:
|
|
100
|
-
client-id: ${QQ_APP_ID}
|
|
101
|
-
client-secret: ${QQ_APP_KEY}
|
|
102
|
-
redirect-uri: ${server.url}/social-callback?source=qq
|
|
103
|
-
union-id: true # 是否获取 unionId
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### 2.2 特殊平台配置
|
|
107
|
-
|
|
108
|
-
#### 微软登录(需要 tenantId)
|
|
109
|
-
|
|
110
|
-
```yaml
|
|
111
|
-
justauth:
|
|
112
|
-
type:
|
|
113
|
-
microsoft:
|
|
114
|
-
client-id: ${MICROSOFT_CLIENT_ID}
|
|
115
|
-
client-secret: ${MICROSOFT_CLIENT_SECRET}
|
|
116
|
-
redirect-uri: ${server.url}/social-callback?source=microsoft
|
|
117
|
-
tenant-id: common # common、organizations、consumers 或具体租户ID
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
#### 企业微信(需要 agentId)
|
|
121
|
-
|
|
122
|
-
```yaml
|
|
123
|
-
justauth:
|
|
124
|
-
type:
|
|
125
|
-
wechat_enterprise:
|
|
126
|
-
client-id: ${WECHAT_CORP_ID}
|
|
127
|
-
client-secret: ${WECHAT_CORP_SECRET}
|
|
128
|
-
redirect-uri: ${server.url}/social-callback?source=wechat_enterprise
|
|
129
|
-
agent-id: ${WECHAT_AGENT_ID}
|
|
53
|
+
client-id: ${DINGTALK_APP_KEY:}
|
|
54
|
+
client-secret: ${DINGTALK_APP_SECRET:}
|
|
55
|
+
redirect-uri: ${justauth.address}/social-callback?source=dingtalk
|
|
130
56
|
```
|
|
131
57
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
```yaml
|
|
135
|
-
justauth:
|
|
136
|
-
type:
|
|
137
|
-
alipay_wallet:
|
|
138
|
-
client-id: ${ALIPAY_APP_ID}
|
|
139
|
-
client-secret: ${ALIPAY_PRIVATE_KEY}
|
|
140
|
-
redirect-uri: ${server.url}/social-callback?source=alipay_wallet
|
|
141
|
-
alipay-public-key: ${ALIPAY_PUBLIC_KEY}
|
|
142
|
-
```
|
|
58
|
+
> 各平台特殊配置(微软 tenantId、企业微信 agentId、支付宝公钥等)详见 `references/provider-configs.md`。
|
|
143
59
|
|
|
144
60
|
---
|
|
145
61
|
|
|
146
62
|
## 三、核心 API
|
|
147
63
|
|
|
148
|
-
### 3.1 SocialUtils
|
|
64
|
+
### 3.1 SocialUtils
|
|
149
65
|
|
|
150
66
|
**位置**:`org.dromara.common.social.utils.SocialUtils`
|
|
151
67
|
|
|
152
68
|
```java
|
|
153
69
|
import org.dromara.common.social.utils.SocialUtils;
|
|
154
|
-
import org.dromara.common.social.config.properties.SocialProperties;
|
|
155
70
|
import me.zhyd.oauth.model.AuthResponse;
|
|
156
71
|
import me.zhyd.oauth.model.AuthUser;
|
|
157
72
|
import me.zhyd.oauth.request.AuthRequest;
|
|
158
73
|
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
// 1. 获取指定平台的授权请求对象
|
|
74
|
+
// 获取授权请求对象
|
|
162
75
|
AuthRequest authRequest = SocialUtils.getAuthRequest("github", socialProperties);
|
|
163
76
|
|
|
164
|
-
//
|
|
165
|
-
String authorizeUrl = authRequest.authorize(
|
|
166
|
-
|
|
167
|
-
// ========== 处理回调登录 ==========
|
|
77
|
+
// 生成授权 URL
|
|
78
|
+
String authorizeUrl = authRequest.authorize(state);
|
|
168
79
|
|
|
169
|
-
//
|
|
80
|
+
// 处理回调登录
|
|
170
81
|
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
|
|
171
|
-
"github",
|
|
172
|
-
code, // 授权码
|
|
173
|
-
state, // 状态码(防 CSRF)
|
|
174
|
-
socialProperties // 配置属性
|
|
82
|
+
"github", code, state, socialProperties
|
|
175
83
|
);
|
|
176
|
-
|
|
177
|
-
// 4. 检查登录结果
|
|
178
84
|
if (response.ok()) {
|
|
179
|
-
AuthUser
|
|
180
|
-
String openId =
|
|
181
|
-
String nickname =
|
|
182
|
-
String
|
|
183
|
-
String source = authUser.getSource(); // 来源平台
|
|
85
|
+
AuthUser user = response.getData();
|
|
86
|
+
String openId = user.getUuid(); // 唯一标识
|
|
87
|
+
String nickname = user.getNickname(); // 昵称
|
|
88
|
+
String source = user.getSource(); // 来源平台
|
|
184
89
|
}
|
|
185
90
|
```
|
|
186
91
|
|
|
187
|
-
### 3.2 AuthUser
|
|
92
|
+
### 3.2 AuthUser 关键字段
|
|
188
93
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
private String avatar; // 头像
|
|
196
|
-
private String blog; // 博客地址
|
|
197
|
-
private String company; // 公司
|
|
198
|
-
private String location; // 位置
|
|
199
|
-
private String email; // 邮箱
|
|
200
|
-
private String remark; // 备注
|
|
201
|
-
private AuthUserGender gender; // 性别
|
|
202
|
-
private String source; // 来源平台(github、gitee 等)
|
|
203
|
-
private AuthToken token; // Token 信息
|
|
204
|
-
private Map<String, Object> rawUserInfo; // 原始用户信息
|
|
205
|
-
}
|
|
206
|
-
```
|
|
94
|
+
| 属性 | 说明 | 属性 | 说明 |
|
|
95
|
+
|------|------|------|------|
|
|
96
|
+
| `uuid` | 平台用户唯一ID | `username` | 用户名 |
|
|
97
|
+
| `nickname` | 昵称 | `avatar` | 头像 |
|
|
98
|
+
| `email` | 邮箱 | `source` | 来源平台 |
|
|
99
|
+
| `token` | Token 信息 | `rawUserInfo` | 原始数据(Map) |
|
|
207
100
|
|
|
208
|
-
### 3.3
|
|
101
|
+
### 3.3 状态缓存
|
|
209
102
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
框架使用 Redis 缓存 OAuth2 state 参数,防止 CSRF 攻击:
|
|
213
|
-
|
|
214
|
-
```java
|
|
215
|
-
// 自动注入,无需手动操作
|
|
216
|
-
// 授权 URL 生成时自动存入 state
|
|
217
|
-
// 回调验证时自动校验 state
|
|
218
|
-
// 默认过期时间:3 分钟
|
|
219
|
-
```
|
|
103
|
+
`AuthRedisStateCache` 自动管理 OAuth2 state 参数(Redis 缓存,3分钟过期),无需手动操作。
|
|
220
104
|
|
|
221
105
|
---
|
|
222
106
|
|
|
223
|
-
##
|
|
224
|
-
|
|
225
|
-
### 4.1 流程图
|
|
107
|
+
## 四、后端实现
|
|
226
108
|
|
|
227
|
-
|
|
228
|
-
┌─────────────┐ 1. 点击第三方登录 ┌─────────────┐
|
|
229
|
-
│ 前端页面 │ ────────────────────────→ │ 后端服务 │
|
|
230
|
-
└─────────────┘ └─────────────┘
|
|
231
|
-
│
|
|
232
|
-
2. 生成授权 URL(含 state)
|
|
233
|
-
│
|
|
234
|
-
▼
|
|
235
|
-
┌─────────────┐ 3. 跳转授权页面 ┌─────────────┐
|
|
236
|
-
│ 前端页面 │ ←─────────────────────── │ 后端服务 │
|
|
237
|
-
└─────────────┘ └─────────────┘
|
|
238
|
-
│
|
|
239
|
-
│ 4. 用户在第三方平台授权
|
|
240
|
-
▼
|
|
241
|
-
┌─────────────┐ 5. 回调(code+state) ┌─────────────┐
|
|
242
|
-
│ 第三方平台 │ ────────────────────────→ │ 后端服务 │
|
|
243
|
-
└─────────────┘ └─────────────┘
|
|
244
|
-
│
|
|
245
|
-
6. 用 code 换取用户信息
|
|
246
|
-
│
|
|
247
|
-
7. 查找绑定关系 / 创建用户
|
|
248
|
-
│
|
|
249
|
-
8. 生成系统 Token
|
|
250
|
-
▼
|
|
251
|
-
┌─────────────┐ 9. 返回登录结果 ┌─────────────┐
|
|
252
|
-
│ 前端页面 │ ←─────────────────────── │ 后端服务 │
|
|
253
|
-
└─────────────┘ └─────────────┘
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
### 4.2 后端实现示例
|
|
257
|
-
|
|
258
|
-
#### 步骤1:生成授权 URL
|
|
109
|
+
### 4.1 生成授权 URL
|
|
259
110
|
|
|
260
111
|
```java
|
|
261
|
-
@
|
|
262
|
-
@
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
private final SocialProperties socialProperties;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* 获取第三方登录授权 URL
|
|
270
|
-
*
|
|
271
|
-
* @param source 平台标识(github、gitee、dingtalk 等)
|
|
272
|
-
*/
|
|
273
|
-
@GetMapping("/binding/{source}")
|
|
274
|
-
public R<String> authBinding(@PathVariable String source) {
|
|
275
|
-
// 获取授权请求对象
|
|
276
|
-
AuthRequest authRequest = SocialUtils.getAuthRequest(source, socialProperties);
|
|
277
|
-
|
|
278
|
-
// 生成随机 state(自动存入 Redis)
|
|
279
|
-
String state = AuthStateUtils.createState();
|
|
280
|
-
|
|
281
|
-
// 生成授权 URL
|
|
282
|
-
String authorizeUrl = authRequest.authorize(state);
|
|
283
|
-
|
|
284
|
-
return R.ok("操作成功", authorizeUrl);
|
|
285
|
-
}
|
|
112
|
+
@GetMapping("/binding/{source}")
|
|
113
|
+
public R<String> authBinding(@PathVariable String source) {
|
|
114
|
+
AuthRequest authRequest = SocialUtils.getAuthRequest(source, socialProperties);
|
|
115
|
+
String state = AuthStateUtils.createState();
|
|
116
|
+
return R.ok("操作成功", authRequest.authorize(state));
|
|
286
117
|
}
|
|
287
118
|
```
|
|
288
119
|
|
|
289
|
-
|
|
120
|
+
### 4.2 回调登录(SocialAuthStrategy)
|
|
290
121
|
|
|
291
122
|
```java
|
|
292
123
|
@Slf4j
|
|
@@ -294,43 +125,28 @@ public class AuthController {
|
|
|
294
125
|
@RequiredArgsConstructor
|
|
295
126
|
public class SocialAuthStrategy implements IAuthStrategy {
|
|
296
127
|
|
|
297
|
-
private final SocialProperties socialProperties;
|
|
298
|
-
private final ISysSocialService sysSocialService;
|
|
299
|
-
private final SysUserMapper userMapper;
|
|
300
|
-
private final SysLoginService loginService;
|
|
301
|
-
|
|
302
128
|
@Override
|
|
303
129
|
public LoginVo login(String body, SysClientVo client) {
|
|
304
130
|
SocialLoginBody loginBody = JsonUtils.parseObject(body, SocialLoginBody.class);
|
|
305
131
|
ValidatorUtils.validate(loginBody);
|
|
306
132
|
|
|
307
|
-
// 1.
|
|
133
|
+
// 1. 获取第三方用户信息
|
|
308
134
|
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
|
|
309
|
-
loginBody.getSource(),
|
|
310
|
-
loginBody.
|
|
311
|
-
loginBody.getSocialState(),
|
|
312
|
-
socialProperties
|
|
313
|
-
);
|
|
314
|
-
|
|
135
|
+
loginBody.getSource(), loginBody.getSocialCode(),
|
|
136
|
+
loginBody.getSocialState(), socialProperties);
|
|
315
137
|
if (!response.ok()) {
|
|
316
138
|
throw new ServiceException(response.getMsg());
|
|
317
139
|
}
|
|
318
140
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
// 2. 根据 authId 查找绑定关系
|
|
322
|
-
String authId = authUserData.getSource() + authUserData.getUuid();
|
|
141
|
+
// 2. 查找绑定关系
|
|
142
|
+
String authId = response.getData().getSource() + response.getData().getUuid();
|
|
323
143
|
List<SysSocialVo> list = sysSocialService.selectByAuthId(authId);
|
|
324
|
-
|
|
325
144
|
if (CollUtil.isEmpty(list)) {
|
|
326
145
|
throw new ServiceException("你还没有绑定第三方账号,绑定后才可以登录!");
|
|
327
146
|
}
|
|
328
147
|
|
|
329
|
-
// 3.
|
|
330
|
-
|
|
331
|
-
LoginUser loginUser = loginService.buildLoginUser(loadUser(social.getUserId()));
|
|
332
|
-
|
|
333
|
-
// 4. 登录并返回 Token
|
|
148
|
+
// 3. 生成系统 Token
|
|
149
|
+
LoginUser loginUser = loginService.buildLoginUser(loadUser(list.get(0).getUserId()));
|
|
334
150
|
LoginHelper.login(loginUser, new SaLoginParameter()
|
|
335
151
|
.setDeviceType(client.getDeviceType())
|
|
336
152
|
.setTimeout(client.getTimeout())
|
|
@@ -344,81 +160,32 @@ public class SocialAuthStrategy implements IAuthStrategy {
|
|
|
344
160
|
}
|
|
345
161
|
```
|
|
346
162
|
|
|
347
|
-
### 4.3
|
|
348
|
-
|
|
349
|
-
绑定入口:`AuthController.socialCallback()` → `SysLoginService.socialRegister()`
|
|
163
|
+
### 4.3 账号绑定
|
|
350
164
|
|
|
351
165
|
```java
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* 前端回调绑定授权(需要token)
|
|
356
|
-
*/
|
|
166
|
+
// 绑定:AuthController.socialCallback() → SysLoginService.socialRegister()
|
|
357
167
|
@PostMapping("/social/callback")
|
|
358
168
|
public R<Void> socialCallback(@RequestBody SocialLoginBody loginBody) {
|
|
359
169
|
StpUtil.checkLogin();
|
|
360
|
-
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
|
|
361
|
-
|
|
362
|
-
loginBody.getSocialState(), socialProperties);
|
|
363
|
-
if (!response.ok()) {
|
|
364
|
-
return R.fail(response.getMsg());
|
|
365
|
-
}
|
|
170
|
+
AuthResponse<AuthUser> response = SocialUtils.loginAuth(...);
|
|
171
|
+
if (!response.ok()) return R.fail(response.getMsg());
|
|
366
172
|
loginService.socialRegister(response.getData());
|
|
367
173
|
return R.ok();
|
|
368
174
|
}
|
|
369
|
-
```
|
|
370
175
|
|
|
371
|
-
|
|
372
|
-
//
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
* 绑定第三方用户
|
|
376
|
-
*/
|
|
377
|
-
@Lock4j
|
|
378
|
-
public void socialRegister(AuthUser authUserData) {
|
|
379
|
-
String authId = authUserData.getSource() + authUserData.getUuid();
|
|
380
|
-
// 第三方用户信息转 BO
|
|
381
|
-
SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class);
|
|
382
|
-
BeanUtil.copyProperties(authUserData.getToken(), bo);
|
|
383
|
-
Long userId = LoginHelper.getUserId();
|
|
384
|
-
bo.setUserId(userId);
|
|
385
|
-
bo.setAuthId(authId);
|
|
386
|
-
bo.setOpenId(authUserData.getUuid());
|
|
387
|
-
bo.setUserName(authUserData.getUsername());
|
|
388
|
-
bo.setNickName(authUserData.getNickname());
|
|
389
|
-
|
|
390
|
-
// 检查是否已被其他用户绑定
|
|
391
|
-
List<SysSocialVo> checkList = sysSocialService.selectByAuthId(authId);
|
|
392
|
-
if (CollUtil.isNotEmpty(checkList)) {
|
|
393
|
-
throw new ServiceException("此三方账号已经被绑定!");
|
|
394
|
-
}
|
|
395
|
-
// 查询当前用户是否已绑定该平台
|
|
396
|
-
SysSocialBo params = new SysSocialBo();
|
|
397
|
-
params.setUserId(userId);
|
|
398
|
-
params.setSource(bo.getSource());
|
|
399
|
-
List<SysSocialVo> list = sysSocialService.queryList(params);
|
|
400
|
-
if (CollUtil.isEmpty(list)) {
|
|
401
|
-
sysSocialService.insertByBo(bo); // 新增绑定
|
|
402
|
-
} else {
|
|
403
|
-
bo.setId(list.get(0).getId());
|
|
404
|
-
sysSocialService.updateByBo(bo); // 更新绑定
|
|
405
|
-
}
|
|
406
|
-
}
|
|
176
|
+
// socialRegister 核心逻辑:
|
|
177
|
+
// 1. 生成 authId = source + uuid
|
|
178
|
+
// 2. 检查 authId 是否已被其他用户绑定
|
|
179
|
+
// 3. 查询当前用户是否已绑定该平台 -> 新增或更新
|
|
407
180
|
```
|
|
408
181
|
|
|
409
|
-
|
|
182
|
+
### 4.4 解绑
|
|
410
183
|
|
|
411
184
|
```java
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* 取消授权(需要token)
|
|
416
|
-
*/
|
|
417
|
-
@DeleteMapping(value = "/unlock/{socialId}")
|
|
185
|
+
@DeleteMapping("/unlock/{socialId}")
|
|
418
186
|
public R<Void> unlockSocial(@PathVariable Long socialId) {
|
|
419
187
|
StpUtil.checkLogin();
|
|
420
|
-
|
|
421
|
-
return rows ? R.ok() : R.fail("取消授权失败");
|
|
188
|
+
return socialUserService.deleteWithValidById(socialId) ? R.ok() : R.fail("取消授权失败");
|
|
422
189
|
}
|
|
423
190
|
```
|
|
424
191
|
|
|
@@ -426,243 +193,74 @@ public R<Void> unlockSocial(@PathVariable Long socialId) {
|
|
|
426
193
|
|
|
427
194
|
## 五、前端集成
|
|
428
195
|
|
|
429
|
-
### 5.1 跳转第三方授权
|
|
430
|
-
|
|
431
196
|
```javascript
|
|
432
|
-
//
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
function handleWeChatLogin() {
|
|
445
|
-
getSocialLoginUrl('wechat_open');
|
|
446
|
-
}
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
### 5.2 处理回调
|
|
450
|
-
|
|
451
|
-
```javascript
|
|
452
|
-
// 回调页面 social-callback.vue
|
|
453
|
-
export default {
|
|
454
|
-
async mounted() {
|
|
455
|
-
const { source, code, state } = this.$route.query;
|
|
456
|
-
|
|
457
|
-
if (!code || !state) {
|
|
458
|
-
this.$message.error('授权失败');
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
try {
|
|
463
|
-
// 调用后端登录接口
|
|
464
|
-
const { data } = await request.post('/auth/login', {
|
|
465
|
-
grantType: 'social',
|
|
466
|
-
source: source,
|
|
467
|
-
socialCode: code,
|
|
468
|
-
socialState: state,
|
|
469
|
-
clientId: 'your-client-id'
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
// 保存 Token
|
|
473
|
-
setToken(data.accessToken);
|
|
474
|
-
|
|
475
|
-
// 跳转首页
|
|
476
|
-
this.$router.push('/');
|
|
477
|
-
} catch (error) {
|
|
478
|
-
this.$message.error(error.message || '登录失败');
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
197
|
+
// 跳转授权
|
|
198
|
+
const { data } = await request.get(`/auth/binding/${source}`);
|
|
199
|
+
window.location.href = data;
|
|
200
|
+
|
|
201
|
+
// 回调页面处理
|
|
202
|
+
const { source, code, state } = this.$route.query;
|
|
203
|
+
const { data } = await request.post('/auth/login', {
|
|
204
|
+
grantType: 'social',
|
|
205
|
+
source, socialCode: code, socialState: state,
|
|
206
|
+
clientId: 'your-client-id'
|
|
207
|
+
});
|
|
208
|
+
setToken(data.accessToken);
|
|
482
209
|
```
|
|
483
210
|
|
|
484
211
|
---
|
|
485
212
|
|
|
486
|
-
##
|
|
487
|
-
|
|
488
|
-
### ❌ 错误1:回调地址配置错误
|
|
213
|
+
## 六、常见错误
|
|
489
214
|
|
|
490
215
|
```yaml
|
|
491
|
-
# ❌
|
|
492
|
-
|
|
493
|
-
type:
|
|
494
|
-
github:
|
|
495
|
-
redirect-uri: http://localhost:8080/callback # 本地地址
|
|
496
|
-
|
|
497
|
-
# ✅ 正确:使用与第三方平台一致的回调地址
|
|
498
|
-
justauth:
|
|
499
|
-
type:
|
|
500
|
-
github:
|
|
501
|
-
redirect-uri: https://your-domain.com/social-callback?source=github
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
### ❌ 错误2:未处理 state 验证失败
|
|
505
|
-
|
|
506
|
-
```java
|
|
507
|
-
// ❌ 错误:不检查响应结果
|
|
508
|
-
AuthResponse<AuthUser> response = SocialUtils.loginAuth(...);
|
|
509
|
-
AuthUser user = response.getData(); // 可能为 null
|
|
510
|
-
|
|
511
|
-
// ✅ 正确:先检查响应状态
|
|
512
|
-
AuthResponse<AuthUser> response = SocialUtils.loginAuth(...);
|
|
513
|
-
if (!response.ok()) {
|
|
514
|
-
throw new ServiceException("授权失败:" + response.getMsg());
|
|
515
|
-
}
|
|
516
|
-
AuthUser user = response.getData();
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
### ❌ 错误3:未处理账号未绑定情况
|
|
216
|
+
# ❌ 回调地址与第三方平台配置不一致
|
|
217
|
+
redirect-uri: http://localhost:8080/callback
|
|
520
218
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
List<SysSocialVo> list = sysSocialService.selectByAuthId(authId);
|
|
524
|
-
SysSocialVo social = list.get(0); // 可能 IndexOutOfBoundsException
|
|
525
|
-
|
|
526
|
-
// ✅ 正确:检查是否已绑定
|
|
527
|
-
List<SysSocialVo> list = sysSocialService.selectByAuthId(authId);
|
|
528
|
-
if (CollUtil.isEmpty(list)) {
|
|
529
|
-
throw new ServiceException("请先绑定第三方账号");
|
|
530
|
-
}
|
|
531
|
-
SysSocialVo social = list.get(0);
|
|
219
|
+
# ✅ 使用与第三方平台一致的地址
|
|
220
|
+
redirect-uri: https://your-domain.com/social-callback?source=github
|
|
532
221
|
```
|
|
533
222
|
|
|
534
|
-
### ❌ 错误4:source 标识拼写错误
|
|
535
|
-
|
|
536
223
|
```java
|
|
537
|
-
// ❌
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
// ✅ 正确:使用正确的 source 标识
|
|
541
|
-
SocialUtils.getAuthRequest("wechat_open", socialProperties); // 微信开放平台
|
|
542
|
-
SocialUtils.getAuthRequest("wechat_mp", socialProperties); // 微信公众号
|
|
543
|
-
SocialUtils.getAuthRequest("wechat_enterprise", socialProperties); // 企业微信
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
---
|
|
547
|
-
|
|
548
|
-
## 七、API 速查表
|
|
549
|
-
|
|
550
|
-
### SocialUtils 方法
|
|
551
|
-
|
|
552
|
-
| 方法 | 说明 |
|
|
553
|
-
|------|------|
|
|
554
|
-
| `getAuthRequest(source, properties)` | 获取指定平台的授权请求对象 |
|
|
555
|
-
| `loginAuth(source, code, state, properties)` | 处理回调登录,获取用户信息 |
|
|
556
|
-
|
|
557
|
-
### AuthRequest 方法
|
|
558
|
-
|
|
559
|
-
| 方法 | 说明 |
|
|
560
|
-
|------|------|
|
|
561
|
-
| `authorize(state)` | 生成授权 URL |
|
|
562
|
-
| `login(callback)` | 执行登录,获取用户信息 |
|
|
563
|
-
| `refresh(token)` | 刷新 Token |
|
|
564
|
-
| `revoke(token)` | 撤销授权 |
|
|
565
|
-
|
|
566
|
-
### AuthUser 属性
|
|
567
|
-
|
|
568
|
-
| 属性 | 说明 |
|
|
569
|
-
|------|------|
|
|
570
|
-
| `uuid` | 第三方平台用户唯一ID |
|
|
571
|
-
| `username` | 用户名 |
|
|
572
|
-
| `nickname` | 昵称 |
|
|
573
|
-
| `avatar` | 头像 URL |
|
|
574
|
-
| `email` | 邮箱 |
|
|
575
|
-
| `source` | 来源平台标识 |
|
|
576
|
-
| `token` | Token 信息(accessToken、refreshToken 等) |
|
|
577
|
-
| `rawUserInfo` | 原始用户信息(Map) |
|
|
578
|
-
|
|
579
|
-
---
|
|
224
|
+
// ❌ 不检查响应结果
|
|
225
|
+
AuthUser user = response.getData(); // 可能 null
|
|
580
226
|
|
|
581
|
-
|
|
227
|
+
// ✅ 先检查状态
|
|
228
|
+
if (!response.ok()) throw new ServiceException(response.getMsg());
|
|
582
229
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
```yaml
|
|
586
|
-
justauth:
|
|
587
|
-
type:
|
|
588
|
-
github:
|
|
589
|
-
client-id: ${GITHUB_CLIENT_ID:}
|
|
590
|
-
client-secret: ${GITHUB_CLIENT_SECRET:}
|
|
591
|
-
redirect-uri: ${justauth.address}/social-callback?source=github
|
|
592
|
-
|
|
593
|
-
gitee:
|
|
594
|
-
client-id: ${GITEE_CLIENT_ID:}
|
|
595
|
-
client-secret: ${GITEE_CLIENT_SECRET:}
|
|
596
|
-
redirect-uri: ${justauth.address}/social-callback?source=gitee
|
|
597
|
-
|
|
598
|
-
dingtalk:
|
|
599
|
-
client-id: ${DINGTALK_APP_KEY:}
|
|
600
|
-
client-secret: ${DINGTALK_APP_SECRET:}
|
|
601
|
-
redirect-uri: ${justauth.address}/social-callback?source=dingtalk
|
|
230
|
+
// ❌ source 标识拼写错误
|
|
231
|
+
SocialUtils.getAuthRequest("wechat", props); // 不存在
|
|
602
232
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
redirect-uri: ${justauth.address}/social-callback?source=qq
|
|
607
|
-
union-id: true
|
|
608
|
-
|
|
609
|
-
wechat_open:
|
|
610
|
-
client-id: ${WECHAT_OPEN_APP_ID:}
|
|
611
|
-
client-secret: ${WECHAT_OPEN_APP_SECRET:}
|
|
612
|
-
redirect-uri: ${justauth.address}/social-callback?source=wechat_open
|
|
613
|
-
|
|
614
|
-
wechat_mp:
|
|
615
|
-
client-id: ${WECHAT_MP_APP_ID:}
|
|
616
|
-
client-secret: ${WECHAT_MP_APP_SECRET:}
|
|
617
|
-
redirect-uri: ${justauth.address}/social-callback?source=wechat_mp
|
|
618
|
-
|
|
619
|
-
maxkey:
|
|
620
|
-
client-id: ${MAXKEY_CLIENT_ID:}
|
|
621
|
-
client-secret: ${MAXKEY_CLIENT_SECRET:}
|
|
622
|
-
redirect-uri: ${justauth.address}/social-callback?source=maxkey
|
|
623
|
-
server-url: ${MAXKEY_SERVER_URL:}
|
|
624
|
-
|
|
625
|
-
# 授权回调地址前缀
|
|
626
|
-
address: https://your-domain.com
|
|
233
|
+
// ✅ 正确标识
|
|
234
|
+
SocialUtils.getAuthRequest("wechat_open", props); // 微信开放平台
|
|
235
|
+
SocialUtils.getAuthRequest("wechat_mp", props); // 微信公众号
|
|
627
236
|
```
|
|
628
237
|
|
|
629
238
|
---
|
|
630
239
|
|
|
631
|
-
##
|
|
632
|
-
|
|
633
|
-
| 类型 | 位置 |
|
|
634
|
-
|------|------|
|
|
635
|
-
| 社交登录工具类 | `ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java` |
|
|
636
|
-
| 状态缓存 | `ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/AuthRedisStateCache.java` |
|
|
637
|
-
| 配置属性 | `ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/config/properties/SocialProperties.java` |
|
|
638
|
-
| 登录配置属性 | `ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/config/properties/SocialLoginConfigProperties.java` |
|
|
639
|
-
| 社交登录策略 | `ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java` |
|
|
640
|
-
| 认证控制器 | `ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java` |
|
|
641
|
-
| 社交绑定服务 | `ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysSocialService.java` |
|
|
642
|
-
|
|
643
|
-
---
|
|
644
|
-
|
|
645
|
-
## 十、扩展:自定义第三方平台
|
|
646
|
-
|
|
647
|
-
如需接入框架未支持的第三方平台,可参考 `AuthGiteaRequest` 实现:
|
|
240
|
+
## 七、扩展自定义平台
|
|
648
241
|
|
|
649
242
|
```java
|
|
650
243
|
public class AuthCustomRequest extends AuthDefaultRequest {
|
|
651
|
-
|
|
652
244
|
public AuthCustomRequest(AuthConfig config, AuthStateCache stateCache) {
|
|
653
245
|
super(config, AuthCustomSource.CUSTOM, stateCache);
|
|
654
246
|
}
|
|
655
|
-
|
|
656
247
|
@Override
|
|
657
|
-
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
|
658
|
-
// 实现获取 Token 的逻辑
|
|
659
|
-
}
|
|
660
|
-
|
|
248
|
+
protected AuthToken getAccessToken(AuthCallback authCallback) { ... }
|
|
661
249
|
@Override
|
|
662
|
-
protected AuthUser getUserInfo(AuthToken authToken) {
|
|
663
|
-
// 实现获取用户信息的逻辑
|
|
664
|
-
}
|
|
250
|
+
protected AuthUser getUserInfo(AuthToken authToken) { ... }
|
|
665
251
|
}
|
|
252
|
+
// 然后在 SocialUtils.getAuthRequest() 中添加对应 case
|
|
666
253
|
```
|
|
667
254
|
|
|
668
|
-
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## 八、参考代码位置
|
|
258
|
+
|
|
259
|
+
| 类型 | 位置 |
|
|
260
|
+
|------|------|
|
|
261
|
+
| SocialUtils | `ruoyi-common/ruoyi-common-social/.../utils/SocialUtils.java` |
|
|
262
|
+
| AuthRedisStateCache | `ruoyi-common/ruoyi-common-social/.../utils/AuthRedisStateCache.java` |
|
|
263
|
+
| SocialProperties | `ruoyi-common/ruoyi-common-social/.../config/properties/SocialProperties.java` |
|
|
264
|
+
| SocialAuthStrategy | `ruoyi-admin/.../web/service/impl/SocialAuthStrategy.java` |
|
|
265
|
+
| AuthController | `ruoyi-admin/.../web/controller/AuthController.java` |
|
|
266
|
+
| ISysSocialService | `ruoyi-modules/ruoyi-system/.../service/ISysSocialService.java` |
|