package com.kidgrow.zuul.service.impl; import cn.hutool.core.util.StrUtil; import com.kidgrow.authclient.util.AuthUtils; import com.kidgrow.zuul.service.TokenService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2RefreshToken; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import javax.servlet.http.HttpServletRequest; @Service public class TokenServiceImpl implements TokenService { @Autowired private TokenStore tokenStore; /** * 退出的接口 * @param request */ @Override public void logout(HttpServletRequest request) { Assert.notNull(tokenStore, "tokenStore must be set"); String token = request.getParameter("token"); if (StrUtil.isEmpty(token)) { token = AuthUtils.extractToken(request); } if(StrUtil.isNotEmpty(token)){ OAuth2AccessToken existingAccessToken = tokenStore.readAccessToken(token); OAuth2RefreshToken refreshToken; if (existingAccessToken != null) { if (existingAccessToken.getRefreshToken() != null) { refreshToken = existingAccessToken.getRefreshToken(); tokenStore.removeRefreshToken(refreshToken); } tokenStore.removeAccessToken(existingAccessToken); } } } }