SpringBoot 整合JWT 实现认证授权服务
1. 引入JWT依赖
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.4.1</version>
</dependency>
2. 创建生成Token工具类
@Service
public class TokenUtil {
public String getToken(UserVO user) {
return JWT.create().withAudience(user.getCUserName()).sign(Algorithm.HMAC256(user.getCPwd()));
}
}
3. 创建拦截器配置
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authenticationInterceptor(