feat: [auth] finished dingtalk login

This commit is contained in:
tjq 2023-04-16 16:40:52 +08:00
parent d789d68180
commit 9bf9746397
5 changed files with 34 additions and 19 deletions

3
.gitignore vendored
View File

@ -43,3 +43,6 @@ build/
*/.txt
*/.trc
powerjob-data/
### local test ###
application-local.properties

View File

@ -13,6 +13,6 @@ import tech.powerjob.server.auth.jwt.SecretProvider;
public class DefaultSecretProvider implements SecretProvider {
@Override
public String fetchSecretKey() {
return "ZQQ";
return "ZQQZJ";
}
}

View File

@ -37,10 +37,10 @@ public class JwtServiceImpl implements JwtService {
* <a href="https://music.163.com/#/song?id=167975">GoodSong</a>
*/
private static final String BASE_SECURITY =
"死去元知万事空" +
"但悲不见九州同" +
"王师北定中原日" +
"家祭无忘告乃翁"
"CengMengXiangZhangJianZouTianYa" +
"KanYiKanShiJieDeFanHua" +
"NianShaoDeXinZongYouXieQingKuang" +
"RuJinWoSiHaiWeiJia"
;
@Override

View File

@ -32,22 +32,29 @@ import java.nio.charset.StandardCharsets;
@Service
public class DingTalkBizLoginService implements BizLoginService {
/*
配置示例
oms.auth.dingtalk.appkey=dinggzqqzqqzqqzqq
oms.auth.dingtalk.appSecret=iY-FS8mzqqzqq_xEizqqzqqzqqzqqzqqzqqYEbkZOal
oms.auth.dingtalk.callbackUrl=http://localhost:7700/auth/loginCallback
*/
/**
* 钉钉应用 AppKey
*/
@Value("${oms.auth.dingtalk.appkey}")
@Value("${oms.auth.dingtalk.appkey:#{null}}")
private String dingTalkAppKey;
/**
* 钉钉应用 AppSecret
*/
@Value("${oms.auth.dingtalk.appSecret}")
@Value("${oms.auth.dingtalk.appSecret:#{null}}")
private String dingTalkAppSecret;
/**
* 回调地址powerjob-server 地址 + /user/auth
* 比如本地调试时为 <a href="http://localhost:7700/user/loginCallback">LocalDemoCallbackUrl</a>
* 部署后则为 <a href="http://try.powerjob.tech/user/loginCallback">demoCallBackUrl</a>
* 比如本地调试时为 <a href="http://localhost:7700/auth/loginCallback">LocalDemoCallbackUrl</a>
* 部署后则为 <a href="http://try.powerjob.tech/auth/loginCallback">demoCallBackUrl</a>
*/
@Value("${oms.auth.dingtalk.callbackUrl}")
@Value("${oms.auth.dingtalk.callbackUrl:#{null}}")
private String dingTalkCallbackUrl;
private static final String DING_TALK = "DingTalk";

View File

@ -71,19 +71,24 @@ public class PowerJobAuthServiceImpl implements PowerJobAuthService {
final BizUser bizUser = loginService.login(loginContext);
String dbUserName = String.format("%s_%s", loginType, bizUser.getUsername());
final Optional<UserInfoDO> powerJobUserOpt = userInfoRepository.findByUsername(dbUserName);
Optional<UserInfoDO> powerJobUserOpt = userInfoRepository.findByUsername(dbUserName);
PowerJobUser ret = new PowerJobUser();
// 存在则响应 PowerJob 用户否则同步在 PowerJob 用户库创建该用户
if (powerJobUserOpt.isPresent()) {
final UserInfoDO dbUser = powerJobUserOpt.get();
BeanUtils.copyProperties(dbUser, ret);
ret.setUsername(dbUserName);
} else {
// 如果不存在用户先同步创建用户
if (!powerJobUserOpt.isPresent()) {
UserInfoDO newUser = new UserInfoDO();
newUser.setUsername(dbUserName);
Loggers.WEB.info("[PowerJobLoginService] sync user to PowerJobUserSystem: {}", dbUserName);
userInfoRepository.saveAndFlush(newUser);
powerJobUserOpt = userInfoRepository.findByUsername(dbUserName);
}
PowerJobUser ret = new PowerJobUser();
// 理论上 100% 存在
if (powerJobUserOpt.isPresent()) {
final UserInfoDO dbUser = powerJobUserOpt.get();
BeanUtils.copyProperties(dbUser, ret);
ret.setUsername(dbUserName);
}