添加登入添加Google Authenticator TOTP六位动态码 授权登。2. 保留Google登录并支持动态码登录
This commit is contained in:
1 parent
42a06f7e4d
commit
cc5fe279e9
13 files changed
+714
-2
No files matched your search
@@ -0,0 +1,67 @@
|
||||
package com.ruoyi.web.controller.system;
|
||||
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.model.LoginBody;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.framework.web.service.TotpAuthService;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/** Authenticator 六位动态码;只有 login 匿名开放,管理接口使用当前 JWT 用户 ID。 */
|
||||
@RestController
|
||||
@RequestMapping("/auth/totp")
|
||||
public class TotpAuthController {
|
||||
private final TotpAuthService service;
|
||||
|
||||
public TotpAuthController(TotpAuthService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@GetMapping("/binding")
|
||||
public AjaxResult status(HttpServletResponse response) {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
return AjaxResult.success(service.status(SecurityUtils.getUserId()));
|
||||
}
|
||||
|
||||
@PostMapping("/setup")
|
||||
public AjaxResult setup(@RequestBody TotpRequest request, HttpServletResponse response) {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
return AjaxResult.success(service.setup(SecurityUtils.getUserId(), request.getPassword()));
|
||||
}
|
||||
|
||||
@PostMapping("/bind")
|
||||
public AjaxResult bind(@RequestBody TotpRequest request) {
|
||||
service.bind(SecurityUtils.getUserId(), request.getPassword(), request.getTotpCode());
|
||||
return AjaxResult.success("Authenticator 已绑定,下一个动态码刷新后可用于登录");
|
||||
}
|
||||
|
||||
@PostMapping("/unbind")
|
||||
public AjaxResult unbind(@RequestBody TotpRequest request) {
|
||||
service.unbind(SecurityUtils.getUserId(), request.getPassword(), request.getTotpCode());
|
||||
return AjaxResult.success("Authenticator 已解绑");
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public AjaxResult login(@RequestBody TotpRequest request, HttpServletRequest servletRequest,
|
||||
HttpServletResponse response) {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
AjaxResult result = AjaxResult.success();
|
||||
result.put(Constants.TOKEN, service.login(request.getUsername(), request.getTotpCode(),
|
||||
request.getCode(), request.getUuid(), servletRequest.getRemoteAddr()));
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 禁止生成包含密码、动态码的 toString;动态码与图形验证码分开传输。 */
|
||||
public static class TotpRequest extends LoginBody {
|
||||
private String totpCode;
|
||||
|
||||
public String getTotpCode() { return totpCode; }
|
||||
public void setTotpCode(String totpCode) { this.totpCode = totpCode; }
|
||||
}
|
||||
}
|
||||
@@ -225,6 +225,13 @@ luqj:
|
||||
dir:
|
||||
prefix: lu7213/images/ # 上传文件夹路径前缀
|
||||
|
||||
# Authenticator 凭据使用独立的 32 字节随机 AES 密钥(Base64),所有实例必须一致。
|
||||
# 留空时禁止新建绑定;不要随意更换,已有凭据需要原密钥才能解密。
|
||||
auth:
|
||||
totp:
|
||||
encryption-key: ${TOTP_ENCRYPTION_KEY:}
|
||||
issuer: ${TOTP_ISSUER:USDT PAY}
|
||||
|
||||
# Google OpenID Connect登录。Client Secret只能通过环境变量或外部配置提供。
|
||||
google:
|
||||
oauth:
|
||||
|
||||
Reference in new issue
Block a user