feat(auth): 新增 Apple 登录并集成 Sa-Token 鉴权

- AppleServiceImpl:返回完整用户信息并签发 Sa-Token
- 新增 KeyboardUser 实体、Mapper、Service,支持按 subjectId 查询与创建
- GlobalExceptionHandler 统一处理 Sa-Token 未登录异常
- 补充 APPLE_LOGIN_ERROR 等错误码
- 配置文件增加 Sa-Token 相关参数
This commit is contained in:
2025-12-02 16:47:01 +08:00
parent bcbb623ee4
commit fdc024e58f
25 changed files with 575 additions and 30 deletions

View File

@@ -34,4 +34,47 @@ apple:
# 根证书路径(从 Apple PKI 下载)
root-certificates:
- "classpath:AppleRootCA-G2.cer"
- "classpath:AppleRootCA-G3.cer"
- "classpath:AppleRootCA-G3.cer"
dromara:
x-file-storage: #文件存储配置
default-platform: cloudflare-r2 #默认使用的存储平台
thumbnail-suffix: ".min.jpg" #缩略图后缀,例如【.min.jpg】【.png】
enable-byte-file-wrapper: false
#对应平台的配置写在这里,注意缩进要对齐
amazon-s3-v2: # Amazon S3 V2
- platform: cloudflare-r2 # 存储平台标识
enable-storage: true # 启用存储
access-key: 550b33cc4d53e05c2e438601f8a0e209
secret-key: df4d529cdae44e6f614ca04f4dc0f1f9a299e57367181243e8abdc7f7c28e99a
region: ENAM # 必填
end-point: https://b632a61caa85401f63c9b32eef3a74c8.r2.cloudflarestorage.com # 必填
bucket-name: keyborad-resource #桶名称
domain: https://resource.loveamorkey.com/ # 访问域名,注意“/”结尾例如https://abcd.s3.ap-east-1.amazonaws.com/
base-path: avatar/ # 基础路径
mailgun:
api-key: ${MAILGUN_API_KEY} # 你的 Private API Key
domain: sandboxxxxxxx.mailgun.org # 或你自己的业务域名
from-email: no-reply@yourdomain.com # 发件人邮箱
from-name: Key Of Love # 发件人名称(可选)
############## Sa-Token 配置 (文档: https://sa-token.cc) ##############
sa-token:
# token 名称(同时也是 cookie 名称)
token-name: auth-token
# token 有效期(单位:秒) 默认30天-1 代表永久有效
timeout: 2592000
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
active-timeout: -1
# 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
is-concurrent: false
# 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token
is-share: false
# token 风格默认可取值uuid、simple-uuid、random-32、random-64、random-128、tik
token-style: random-128
# 是否输出操作日志
is-log: true

View File

@@ -1,6 +1,6 @@
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/postgres
url: jdbc:postgresql://localhost:5432/keyborad_db
username: root
password: 123asd

View File

@@ -15,11 +15,6 @@ spring:
name: keyborad-backend
profiles:
active: dev
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/keyborad_db
username: root
password: 123asd
mvc:
pathmatch:
matching-strategy: ANT_PATH_MATCHER
@@ -44,7 +39,7 @@ server:
enabled: true
mybatis-plus:
configuration:
map-underscore-to-camel-case: false
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
global-config:
db-config:

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yolo.keyborad.mapper.KeyboardUserMapper">
<resultMap id="BaseResultMap" type="com.yolo.keyborad.model.entity.KeyboardUser">
<!--@mbg.generated-->
<!--@Table keyboard_user-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="uid" jdbcType="BIGINT" property="uid" />
<result column="nick_name" jdbcType="VARCHAR" property="nickName" />
<result column="gender" jdbcType="INTEGER" property="gender" />
<result column="avatar_url" jdbcType="VARCHAR" property="avatarUrl" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="deleted" jdbcType="BOOLEAN" property="deleted" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="status" jdbcType="BOOLEAN" property="status" />
<result column="password" jdbcType="VARCHAR" property="password" />
<result column="subject_id" jdbcType="VARCHAR" property="subjectId" />
<result column="email_verified" jdbcType="BOOLEAN" property="emailVerified" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, "uid", nick_name, gender, avatar_url, created_at, updated_at, deleted, email,
"status", "password", subject_id, email_verified
</sql>
</mapper>