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

@@ -1,5 +1,6 @@
package com.yolo.keyborad.exception;
import cn.dev33.satoken.exception.NotLoginException;
import com.yolo.keyborad.common.BaseResponse;
import com.yolo.keyborad.common.ErrorCode;
import com.yolo.keyborad.common.ResultUtils;
@@ -59,4 +60,49 @@ public class GlobalExceptionHandler {
return ResultUtils.error(ErrorCode.SYSTEM_ERROR.getCode(), errorMessage);
}
// 全局异常拦截拦截项目中的NotLoginException异常
@ExceptionHandler(NotLoginException.class)
public BaseResponse<?> handlerNotLoginException(NotLoginException nle)
throws Exception {
// 打印堆栈,以供调试
log.error("handlerNotLoginException", nle);
// 判断场景值,定制化异常信息
String message = "";
if(nle.getType().equals(NotLoginException.NOT_TOKEN)) {
message = "未能读取到有效用户令牌";
return ResultUtils.error(ErrorCode.TOKEN_NOT_FOUND);
}
else if(nle.getType().equals(NotLoginException.INVALID_TOKEN)) {
message = "令牌无效";
return ResultUtils.error(ErrorCode.TOKEN_INVALID);
}
else if(nle.getType().equals(NotLoginException.TOKEN_TIMEOUT)) {
message = "令牌已过期";
return ResultUtils.error(ErrorCode.TOKEN_TIMEOUT);
}
else if(nle.getType().equals(NotLoginException.BE_REPLACED)) {
message = "令牌已被顶下线";
return ResultUtils.error(ErrorCode.TOKEN_BE_REPLACED);
}
else if(nle.getType().equals(NotLoginException.KICK_OUT)) {
message = "令牌已被踢下线";
return ResultUtils.error(ErrorCode.TOKEN_KICK_OUT);
}
else if(nle.getType().equals(NotLoginException.TOKEN_FREEZE)) {
message = "令牌已被冻结";
return ResultUtils.error(ErrorCode.TOKEN_FREEZE);
}
else if(nle.getType().equals(NotLoginException.NO_PREFIX)) {
message = "未按照指定前缀提交令牌";
return ResultUtils.error(ErrorCode.TOKEN_NO_PREFIX);
}
else {
message = "当前会话未登录";
return ResultUtils.error(ErrorCode.NOT_LOGIN_ERROR);
}
}
}