| | |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.UUID; |
| | | |
| | | import com.ruoyi.common.annotation.Anonymous; |
| | | import com.ruoyi.common.config.SsoBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private SsoBean ssoBean; |
| | | |
| | | /** |
| | | * 登录方法 |
| | |
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); |
| | | return AjaxResult.success(menuService.buildMenus(menus)); |
| | | } |
| | | |
| | | /** |
| | | * 获取统一登录平台获取CODE地址 |
| | | * |
| | | * @return |
| | | */ |
| | | |
| | | @GetMapping("/getSsoAuthUrl") |
| | | public AjaxResult getSsoAuthUrl() { |
| | | String uuid = UUID.randomUUID().toString(); |
| | | return AjaxResult.success("操作成功", ssoBean.getUrl() + "/oauth2/auth?response_type=code&scope=openid&client_id=" + ssoBean.getClientId() + "&redirect_uri=" + ssoBean.getCallbackUrl() + "&state=" + uuid); |
| | | } |
| | | |
| | | /** |
| | | * 单点登录 |
| | | * |
| | | * @param code 登录信息 |
| | | * @return 结果 |
| | | */ |
| | | @PostMapping("/loginBySSO") |
| | | public AjaxResult loginBySSO(String code) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | String token = loginService.loginBySSO(code); |
| | | ajax.put(Constants.TOKEN, token); |
| | | return ajax; |
| | | } |
| | | } |