优化 yudao-sso-demo-by-code 的代码

This commit is contained in:
YunaiV 2022-10-03 17:52:51 +08:00
parent f634ecf7c3
commit 6be30c0887
4 changed files with 35 additions and 35 deletions

View File

@ -52,7 +52,7 @@ public class AuthController {
*/
@PostMapping("/logout")
public CommonResult<Boolean> logout(HttpServletRequest request) {
String token = SecurityUtils.obtainAuthorization(request, "Authentication");
String token = SecurityUtils.obtainAuthorization(request, "Authorization");
if (StrUtil.isNotBlank(token)) {
return oauth2Client.revokeToken(token);
}

View File

@ -32,7 +32,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
// 1. 获得访问令牌
String token = SecurityUtils.obtainAuthorization(request, "Authentication");
String token = SecurityUtils.obtainAuthorization(request, "Authorization");
if (StringUtils.hasText(token)) {
// 2. 基于 token 构建登录用户
LoginUser loginUser = buildLoginUserByToken(token);

View File

@ -34,7 +34,7 @@
url: "http://127.0.0.1:18080/user/update?nickname=" + nickname,
method: 'PUT',
headers: {
'Authentication': 'Bearer ' + accessToken
'Authorization': 'Bearer ' + accessToken
},
success: function (result) {
if (result.code !== 0) {
@ -87,7 +87,7 @@
url: "http://127.0.0.1:18080/auth/logout",
method: 'POST',
headers: {
'Authentication': 'Bearer ' + accessToken
'Authorization': 'Bearer ' + accessToken
},
success: function (result) {
if (result.code !== 0) {
@ -120,7 +120,7 @@
url: "http://127.0.0.1:18080/user/get",
method: 'GET',
headers: {
'Authentication': 'Bearer ' + accessToken
'Authorization': 'Bearer ' + accessToken
},
success: function (result) {
if (result.code !== 0) {
@ -134,17 +134,17 @@
</script>
</head>
<body>
<!-- 情况一未登录1跳转 ruoyi-vue-pro 的 SSO 登录页 -->
<div id="noLoginDiv" style="display: none">
<!-- 情况一未登录1跳转 ruoyi-vue-pro 的 SSO 登录页 -->
<div id="noLoginDiv" style="display: none">
您未登录,点击 <a href="#" onclick="ssoLogin()">跳转 </a> SSO 单点登录
</div>
</div>
<!-- 情况二已登录1展示用户信息2刷新访问令牌3退出登录 -->
<div id="yesLoginDiv" style="display: none">
<!-- 情况二已登录1展示用户信息2刷新访问令牌3退出登录 -->
<div id="yesLoginDiv" style="display: none">
您已登录!<button onclick="logout()">退出登录</button> <br />
昵称:<span id="nicknameSpan"> 加载中... </span> <button onclick="updateNickname()">修改昵称</button> <br />
访问令牌:<span id="accessTokenSpan"> 加载中... </span> <button onclick="refreshToken()">刷新令牌</button> <br />
</div>
</div>
</body>
<style>
body { /** 页面居中 */