mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: [auth] finished dingtalk login
This commit is contained in:
parent
d789d68180
commit
9bf9746397
3
.gitignore
vendored
3
.gitignore
vendored
@ -43,3 +43,6 @@ build/
|
|||||||
*/.txt
|
*/.txt
|
||||||
*/.trc
|
*/.trc
|
||||||
powerjob-data/
|
powerjob-data/
|
||||||
|
|
||||||
|
### local test ###
|
||||||
|
application-local.properties
|
@ -13,6 +13,6 @@ import tech.powerjob.server.auth.jwt.SecretProvider;
|
|||||||
public class DefaultSecretProvider implements SecretProvider {
|
public class DefaultSecretProvider implements SecretProvider {
|
||||||
@Override
|
@Override
|
||||||
public String fetchSecretKey() {
|
public String fetchSecretKey() {
|
||||||
return "ZQQ";
|
return "ZQQZJ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,10 @@ public class JwtServiceImpl implements JwtService {
|
|||||||
* <a href="https://music.163.com/#/song?id=167975">GoodSong</a>
|
* <a href="https://music.163.com/#/song?id=167975">GoodSong</a>
|
||||||
*/
|
*/
|
||||||
private static final String BASE_SECURITY =
|
private static final String BASE_SECURITY =
|
||||||
"死去元知万事空" +
|
"CengMengXiangZhangJianZouTianYa" +
|
||||||
"但悲不见九州同" +
|
"KanYiKanShiJieDeFanHua" +
|
||||||
"王师北定中原日" +
|
"NianShaoDeXinZongYouXieQingKuang" +
|
||||||
"家祭无忘告乃翁"
|
"RuJinWoSiHaiWeiJia"
|
||||||
;
|
;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,22 +32,29 @@ import java.nio.charset.StandardCharsets;
|
|||||||
@Service
|
@Service
|
||||||
public class DingTalkBizLoginService implements BizLoginService {
|
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
|
* 钉钉应用 AppKey
|
||||||
*/
|
*/
|
||||||
@Value("${oms.auth.dingtalk.appkey}")
|
@Value("${oms.auth.dingtalk.appkey:#{null}}")
|
||||||
private String dingTalkAppKey;
|
private String dingTalkAppKey;
|
||||||
/**
|
/**
|
||||||
* 钉钉应用 AppSecret
|
* 钉钉应用 AppSecret
|
||||||
*/
|
*/
|
||||||
@Value("${oms.auth.dingtalk.appSecret}")
|
@Value("${oms.auth.dingtalk.appSecret:#{null}}")
|
||||||
private String dingTalkAppSecret;
|
private String dingTalkAppSecret;
|
||||||
/**
|
/**
|
||||||
* 回调地址,powerjob-server 地址 + /user/auth
|
* 回调地址,powerjob-server 地址 + /user/auth
|
||||||
* 比如本地调试时为 <a href="http://localhost:7700/user/loginCallback">LocalDemoCallbackUrl</a>
|
* 比如本地调试时为 <a href="http://localhost:7700/auth/loginCallback">LocalDemoCallbackUrl</a>
|
||||||
* 部署后则为 <a href="http://try.powerjob.tech/user/loginCallback">demoCallBackUrl</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 String dingTalkCallbackUrl;
|
||||||
|
|
||||||
private static final String DING_TALK = "DingTalk";
|
private static final String DING_TALK = "DingTalk";
|
||||||
|
@ -71,19 +71,24 @@ public class PowerJobAuthServiceImpl implements PowerJobAuthService {
|
|||||||
final BizUser bizUser = loginService.login(loginContext);
|
final BizUser bizUser = loginService.login(loginContext);
|
||||||
|
|
||||||
String dbUserName = String.format("%s_%s", loginType, bizUser.getUsername());
|
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()) {
|
||||||
if (powerJobUserOpt.isPresent()) {
|
|
||||||
final UserInfoDO dbUser = powerJobUserOpt.get();
|
|
||||||
BeanUtils.copyProperties(dbUser, ret);
|
|
||||||
ret.setUsername(dbUserName);
|
|
||||||
} else {
|
|
||||||
UserInfoDO newUser = new UserInfoDO();
|
UserInfoDO newUser = new UserInfoDO();
|
||||||
newUser.setUsername(dbUserName);
|
newUser.setUsername(dbUserName);
|
||||||
Loggers.WEB.info("[PowerJobLoginService] sync user to PowerJobUserSystem: {}", dbUserName);
|
Loggers.WEB.info("[PowerJobLoginService] sync user to PowerJobUserSystem: {}", dbUserName);
|
||||||
userInfoRepository.saveAndFlush(newUser);
|
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);
|
ret.setUsername(dbUserName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user