Online studies - Day 17 - Lecture - user authentication four Zuul

2.3.4  configure the proxy forwards 
on top to achieve display the current user information required by the Home Home Nginx request certification service agent, you need to configure the generations on the home page of the virtual host management path: 

#认证
location ^~ /openapi/auth/ {
proxy_pass http://auth_server_pool/auth/;
}

Note: Other front-end system to access authentication request to the authentication service proxy path need to configure the upper side. 
user exits 
3.1  requirements analysis 
procedure is as follows: 
1 , the user clicks the exit pop-up exit confirmation window, click OK to

 
the user exits to the following actions: 
1 , delete redis the token 
2 , delete the cookie in the token 
3.2 API 
certification services provide external exit interface.

@ApiOperation("退出")
public ResponseResult logout();

3.3  server 
certification service provider exit interface. 
3.3.1 DAO 
no.

3.3.2 Service

//从redis中删除令牌
public boolean delToken(String access_token){
String name = "user_token:" + access_token;
stringRedisTemplate.delete(name);
return true;
}

3.3.3 Controller

//退出
@Override
@PostMapping("/userlogout")
public ResponseResult logout() {
//取出身份令牌
String uid = getTokenFormCookie();
//删除redis中token
authService.delToken(uid);
//清除cookie
clearCookie(uid);
return new ResponseResult(CommonCode.SUCCESS);
}
//清除cookie
private void clearCookie(String token){
CookieUtil.addCookie(response, cookieDomain, "/", "uid", token, 0, false);
}

3.3.4 Exit URL clearance 
certification services should check the default user identity information, here you need to withdraw url release. 
In WebSecurityConfifig class override  confifigure (WebSecurity web) method as follows:

@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/userlogin","/userlogout");
}

 

Published 835 original articles · won praise 152 · Views 140,000 +

Guess you like

Origin blog.csdn.net/qq_40208605/article/details/104394237