ruoyi框架的改造参考这篇文章
若依ruoyi框架实现单点登录或者接入统一认证_若依非分离单点登录-CSDN博客
个人理解,可能有不对的地方)
我们只需要修改3.2部分 重写LoginSsoController 以及login_sso.vue页面即可
导入依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>5.8.23</version>
</dependency>
login_sso.vue页面中loginSso()方法
loginSso(){
//
//获取地址栏中的code
const code = this.$route.query.code;
console.log("code="+code)
//调用登录的接口
if(code==''||code==undefined||code==null){
//请求中不带code
window.location.replace("http://maxkey-ip:maxkey-port/sign/authz/oauth/v20/authorize?client_id=936712127312297984&response_type=code&redirect_uri=http://ruoyi-ip:ruoyi-port/loginSso");
}else{
this.loading = true;//开启过渡动画
const loginInfo = {
"code" : code,
};
console.log("code====",code);
//执行另一套登录操作
//不是本系统的用户,去J平台登陆去
this.$store.dispatch("LoginSso", loginInfo).then(() => {
this.$message.success("登录成功");
this.loading = false;
//判断当前角色
getInfo().then((res) => {
//处理登录
this.$router.push({path: this.redirect || "/"}).catch(() => {});
});
}).catch(err=> {
console.log("有异常信息",err);
this.loading = false;
});
}
},
参考MaxKey官网流程
LoginSsoController
/**
* 单点登录Controller
* @author sgc
*/
@Slf4j
@RestController
public class LoginSsoController {
@Autowired
private SysLoginService loginService;
@PostMapping("/loginSso")
public AjaxResult loginSso(String code) {
String body = HttpRequest.get("http://maxkey-ip:maxkey-port/sign/authz/oauth/v20/token?client_id=936712127312297984&client_secret=hnlqMjUxMjIwMjMxNzIwNDAwNTMkgn&grant_type=authorization_code&redirect_uri=http://ruoyi-ip:ruoyi-port/loginSso&code=" + code).execute().body();
JSONObject jsonObject = JSONObject.parseObject(body);
String accesToken = jsonObject.getString("access_token");
String body2 = HttpRequest.get("http://maxkey-ip:maxkey-port/sign/api/oauth/v20/me?access_token=" + accesToken).execute().body();
JSONObject jsonObject2 = JSONObject.parseObject(body2);
String userid = jsonObject2.getString("userid");
//这里进行单点登录上级系统的令牌校验 写自己的逻辑
System.out.println("调用Sso");
AjaxResult ajax = null;
//生成本系统的令牌给到前端进行登录
ajax = AjaxResult.success();
//这里设置单点登录用户默认密码为
String tokenNew = loginService.loginNoCaptcha(userid, "admin123", null);
ajax.put("token", tokenNew);
ajax.put("msg", "登录成功");
return ajax;
}
}
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。