视频地址:

https://www.bilibili.com/video/BV12D4y1U7D8?p=44

有用到Redis存储JWT,头疼每次找Windows版的

https://github.com/MicrosoftArchive/redis/releases

20.09.29获取的下载地址:

https://github.com/microsoftarchive/redis/releases/download/win-3.2.100/Redis-x64-3.2.100.msi

1、移除之前工程中的Redis配置:

POM依赖移除

<!--<dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-redis</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!-- <groupId>org.apache.commons</groupId>-->
<!-- <artifactId>commons-pool2</artifactId>-->
<!--</dependency>-->

YML配置移除:

spring:
redis:
host: localhost

Redis配置类移除:

package cn.zeal4j.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; /**
* @author Administrator
* @file Spring-Security + Oauth2
* @create 2020 09 29 17:16
*/
@Configuration
public class RedisConfiguration { @Autowired
private RedisConnectionFactory redisConnectionFactory; @Bean
public TokenStore getRedisTokenStore() {
return new RedisTokenStore(redisConnectionFactory);
} }

数据源注入和Redis存储移除:

package cn.zeal4j.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore; /**
* @author Administrator
* @file Spring-Security + Oauth2
* @create 2020 09 29 11:48
* @description 授权服务器配置
*/
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { @Autowired
private PasswordEncoder passwordEncoder; @Autowired
private AuthenticationManager authenticationManager;
@Qualifier("customUserDetailsServiceImpl")
@Autowired
private UserDetailsService userDetailsService; // @Qualifier("getRedisTokenStore")
// @Autowired
// private TokenStore tokenStore;
/**
* 使用密码模式需要的配置方法
* @param endpoints
* @throws Exception
*/
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.
authenticationManager(authenticationManager).
userDetailsService(userDetailsService);
// tokenStore(tokenStore);
} @Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.
inMemory().
withClient("admin").
secret(passwordEncoder.encode("112233")).
// accessTokenValiditySeconds(3600). // 令牌有效时间 一小时
redirectUris("http://www.baidu.com"). // 授权成功的跳转
scopes("all"). // 所有范围
// authorizedGrantTypes("authorization_code"); // 授权类型:授权码模式
authorizedGrantTypes("password"); // 授权类型:密码模式
}
}

2、编写JWT配置:

package cn.zeal4j.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
/**
* @author Administrator
* @file IntelliJ IDEA Spring-Security + Oauth2
* @create 2020 09 29 22:36
*/
@Configuration
public class JwtTokenStoreConfiguration { @Bean
public TokenStore getTokenStore(JwtAccessTokenConverter getJwtAccessTokenConverter) {
return new JwtTokenStore(getJwtAccessTokenConverter);
} @Bean
public JwtAccessTokenConverter getJwtAccessTokenConverter() {
JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
jwtAccessTokenConverter.setSigningKey("这不是盐【滑稽】 It's not salt [funny]");
return jwtAccessTokenConverter;
}
}

然后更改授权配置类:

package cn.zeal4j.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; /**
* @author Administrator
* @file Spring-Security + Oauth2
* @create 2020 09 29 11:48
* @description 授权服务器配置
*/
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { @Autowired
private PasswordEncoder passwordEncoder; @Autowired
private AuthenticationManager authenticationManager;
@Qualifier("customUserDetailsServiceImpl")
@Autowired
private UserDetailsService userDetailsService; @Qualifier("getTokenStore")
@Autowired
private TokenStore tokenStore; @Qualifier("getJwtAccessTokenConverter")
@Autowired
private JwtAccessTokenConverter jwtAccessTokenConverter;
// @Qualifier("getRedisTokenStore")
// @Autowired
// private TokenStore tokenStore; /**
* 使用密码模式需要的配置方法
* @param endpoints
* @throws Exception
*/
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.
authenticationManager(authenticationManager).
userDetailsService(userDetailsService).accessTokenConverter(jwtAccessTokenConverter);
// tokenStore(tokenStore);
} @Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.
inMemory().
withClient("admin").
secret(passwordEncoder.encode("112233")).
// accessTokenValiditySeconds(3600). // 令牌有效时间 一小时
redirectUris("http://www.baidu.com"). // 授权成功的跳转
scopes("all"). // 所有范围
// authorizedGrantTypes("authorization_code"); // 授权类型:授权码模式
authorizedGrantTypes("password"); // 授权类型:密码模式
}
}

启动工程,Postman测试:

之前的接口的设置都不需要改变,还是之前的密码模式授权,这里就得到了JWT令牌

把令牌复制到JWT官网的解析工具进行解析查看:

https://jwt.io/#debugger-io

3、JWT自定义申明内容

package cn.zeal4j.configuration;

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer; import java.util.HashMap;
import java.util.Map; /**
* @author Administrator
* @file IntelliJ IDEA Spring-Security + Oauth2
* @create 2020 09 29 23:18
*/
public class CustomJwtTokenEnhancer implements TokenEnhancer { @Override
public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("jwt-key-aaa", "jwt-value-AAA");
map.put("jwt-key-bbb", "jwt-value-BBB");
map.put("jwt-key-ccc", "jwt-value-CCC"); DefaultOAuth2AccessToken defaultOAuth2AccessToken = (DefaultOAuth2AccessToken)oAuth2AccessToken;
defaultOAuth2AccessToken.setAdditionalInformation(map); return defaultOAuth2AccessToken;
}
}

注入增强实现类:

package cn.zeal4j.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
/**
* @author Administrator
* @file IntelliJ IDEA Spring-Security + Oauth2
* @create 2020 09 29 22:36
*/
@Configuration
public class JwtTokenStoreConfiguration { @Bean
public TokenStore getTokenStore(JwtAccessTokenConverter getJwtAccessTokenConverter) {
return new JwtTokenStore(getJwtAccessTokenConverter);
} @Bean
public JwtAccessTokenConverter getJwtAccessTokenConverter() {
JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
jwtAccessTokenConverter.setSigningKey("这不是盐【滑稽】 It's not salt [funny]");
return jwtAccessTokenConverter;
} @Bean
public TokenEnhancer getJwtTokenEnhancer() {
return new
CustomJwtTokenEnhancer();
}

}

注入增强器和配置增强方法:

package cn.zeal4j.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; import java.util.ArrayList;
import java.util.List; /**
* @author Administrator
* @file Spring-Security + Oauth2
* @create 2020 09 29 11:48
* @description 授权服务器配置
*/
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { @Autowired
private PasswordEncoder passwordEncoder; @Autowired
private AuthenticationManager authenticationManager;
@Qualifier("customUserDetailsServiceImpl")
@Autowired
private UserDetailsService userDetailsService; @Qualifier("getTokenStore")
@Autowired
private TokenStore tokenStore; @Qualifier("getJwtAccessTokenConverter")
@Autowired
private JwtAccessTokenConverter jwtAccessTokenConverter; @Qualifier("getJwtTokenEnhancer")
@Autowired
private TokenEnhancer tokenEnhancer;
// @Qualifier("getRedisTokenStore")
// @Autowired
// private TokenStore tokenStore; /**
* 使用密码模式需要的配置方法
* @param endpoints
* @throws Exception
*/
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { // - - - - - 配置JWT自定义申明增强 Starter - - - - -
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
List<TokenEnhancer> tokenEnhancerList = new ArrayList<>(); tokenEnhancerList.add(tokenEnhancer);
tokenEnhancerList.add(jwtAccessTokenConverter); tokenEnhancerChain.setTokenEnhancers(tokenEnhancerList);
// - - - - - 配置JWT自定义申明增强 End - - - - -
endpoints.
authenticationManager(authenticationManager).
userDetailsService(userDetailsService).
accessTokenConverter(jwtAccessTokenConverter).
tokenEnhancer(tokenEnhancerChain);
// tokenStore(tokenStore);
} @Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.
inMemory().
withClient("admin").
secret(passwordEncoder.encode("112233")).
// accessTokenValiditySeconds(3600). // 令牌有效时间 一小时
redirectUris("http://www.baidu.com"). // 授权成功的跳转
scopes("all"). // 所有范围
// authorizedGrantTypes("authorization_code"); // 授权类型:授权码模式
authorizedGrantTypes("password"); // 授权类型:密码模式
}
}

重启项目,进行Postman测试:

在增强器中设置的申明都在这里传输了:

{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbImFsbCJdLCJleHAiOjE2MDE0MzcxODEsImp3dC1rZXktYWFhIjoiand0LXZhbHVlLUFBQSIsImF1dGhvcml0aWVzIjpbImFkbWluIl0sImp0aSI6ImFlYzQ1ZDY1LWRmODMtNDE0Ni04OWEzLTMyMGQ2OTcwZjk1YiIsImp3dC1rZXktYmJiIjoiand0LXZhbHVlLUJCQiIsImNsaWVudF9pZCI6ImFkbWluIiwiand0LWtleS1jY2MiOiJqd3QtdmFsdWUtQ0NDIn0.U_eZFS802BVjobMQlL-nDIxhuoPHRRHxjgQ0ub9Kjos",
"token_type": "bearer",
"expires_in": 43199,
"scope": "all",
"jwt-key-aaa": "jwt-value-AAA",
"jwt-key-bbb": "jwt-value-BBB",
"jwt-key-ccc": "jwt-value-CCC",
"jti": "aec45d65-df83-4146-89a3-320d6970f95b"
}

在令牌解析中同样也存入了

4、JWT解析:

加入JWT解析组件:

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>

新加一个资源获取的接口:

演示中是对原接口更改,我这里就保留不动了

package cn.zeal4j.controller;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.JwtParser;
import io.jsonwebtoken.Jwts;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets; /**
* @author Administrator
* @file Spring-Security + Oauth2
* @create 2020 09 29 12:01
*/
@Controller
@RequestMapping("user")
public class UserController { /**
* 获取当前用户
* @param authentication
* @return user/getCurrentUser
*/
@RequestMapping("/getCurrentUser")
@ResponseBody
public Object getCurrentUser(Authentication authentication) {
return authentication.getPrincipal();
} /**
* 获取当前用户
* @param authentication
* @return user/getCurrentUser
*/
@RequestMapping("/getJwtToken")
@ResponseBody
public Object getJwtToken(HttpServletRequest httpServletRequest, Authentication authentication) {
String authorization = httpServletRequest.getHeader("Authorization");
String token = authorization.substring(authorization.indexOf("bearer") + 7); JwtParser jwtParser = Jwts.parser();
Jws<Claims> claimsJws = jwtParser.
setSigningKey("这不是盐【滑稽】 It's not salt [funny]".getBytes(StandardCharsets.UTF_8)).
parseClaimsJws(token); Claims claimsJwsBody = claimsJws.getBody(); return
claimsJwsBody;
}
}

启动项目:还是一样,第一步Postman获取JWT令牌

{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbImFsbCJdLCJleHAiOjE2MDE0MzgyNzEsImp3dC1rZXktYWFhIjoiand0LXZhbHVlLUFBQSIsImF1dGhvcml0aWVzIjpbImFkbWluIl0sImp0aSI6IjMxMjkzMDhjLTIxYTUtNDdiMi04NzgzLTYyMzFhYzZmZGUxOCIsImp3dC1rZXktYmJiIjoiand0LXZhbHVlLUJCQiIsImNsaWVudF9pZCI6ImFkbWluIiwiand0LWtleS1jY2MiOiJqd3QtdmFsdWUtQ0NDIn0.-88MIBBjqnAynPaGw1_5V1g031SkTxhpmC-ARMKh0iA",
"token_type": "bearer",
"expires_in": 43199,
"scope": "all",
"jwt-key-aaa": "jwt-value-AAA",
"jwt-key-bbb": "jwt-value-BBB",
"jwt-key-ccc": "jwt-value-CCC",
"jti": "3129308c-21a5-47b2-8783-6231ac6fde18"
}

然后Postman访问获取接口:

http://localhost:8080/user/getJwtToken

传输的响应头信息:

KEY -> Authorization
VALUE -> bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbImFsbCJdLCJleHAiOjE2MDE0MzgyNzEsImp3dC1rZXktYWFhIjoiand0LXZhbHVlLUFBQSIsImF1dGhvcml0aWVzIjpbImFkbWluIl0sImp0aSI6IjMxMjkzMDhjLTIxYTUtNDdiMi04NzgzLTYyMzFhYzZmZGUxOCIsImp3dC1rZXktYmJiIjoiand0LXZhbHVlLUJCQiIsImNsaWVudF9pZCI6ImFkbWluIiwiand0LWtleS1jY2MiOiJqd3QtdmFsdWUtQ0NDIn0.-88MIBBjqnAynPaGw1_5V1g031SkTxhpmC-ARMKh0iA

解析出来的JSON数据

{
"user_name": "admin",
"scope": [
"all"
],
"exp": 1601438271,
"jwt-key-aaa": "jwt-value-AAA",
"authorities": [
"admin"
],
"jti": "3129308c-21a5-47b2-8783-6231ac6fde18",
"jwt-key-bbb": "jwt-value-BBB",
"client_id": "admin",
"jwt-key-ccc": "jwt-value-CCC"
}

5、刷新令牌

package cn.zeal4j.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; import java.util.ArrayList;
import java.util.List; /**
* @author Administrator
* @file Spring-Security + Oauth2
* @create 2020 09 29 11:48
* @description 授权服务器配置
*/
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { @Autowired
private PasswordEncoder passwordEncoder; @Autowired
private AuthenticationManager authenticationManager;
@Qualifier("customUserDetailsServiceImpl")
@Autowired
private UserDetailsService userDetailsService; @Qualifier("getTokenStore")
@Autowired
private TokenStore tokenStore; @Qualifier("getJwtAccessTokenConverter")
@Autowired
private JwtAccessTokenConverter jwtAccessTokenConverter; @Qualifier("getJwtTokenEnhancer")
@Autowired
private TokenEnhancer tokenEnhancer; // @Qualifier("getRedisTokenStore")
// @Autowired
// private TokenStore tokenStore; /**
* 使用密码模式需要的配置方法
* @param endpoints
* @throws Exception
*/
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { // - - - - - 配置JWT自定义申明增强 Starter - - - - -
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
List<TokenEnhancer> tokenEnhancerList = new ArrayList<>(); tokenEnhancerList.add(tokenEnhancer);
tokenEnhancerList.add(jwtAccessTokenConverter); tokenEnhancerChain.setTokenEnhancers(tokenEnhancerList);
// - - - - - 配置JWT自定义申明增强 End - - - - - endpoints.
authenticationManager(authenticationManager).
userDetailsService(userDetailsService).
accessTokenConverter(jwtAccessTokenConverter).
tokenEnhancer(tokenEnhancerChain);
// tokenStore(tokenStore);
} @Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.
inMemory().
withClient("admin").
secret(passwordEncoder.encode("112233")).
// accessTokenValiditySeconds(3600). // 令牌有效时间 一小时
redirectUris("http://www.baidu.com"). // 授权成功的跳转
scopes("all"). // 所有范围
// authorizedGrantTypes("authorization_code"); // 授权类型:授权码模式
authorizedGrantTypes("password", "refresh_token", "authorization_code"); // 授权类型:密码模式 追加令牌刷新,和兼容授权码模式
}
}

重启项目:继续请求JWT令牌

这个时候会发现多了一个刷新的令牌:

{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbImFsbCJdLCJleHAiOjE2MDE0Mzg4NTAsImp3dC1rZXktYWFhIjoiand0LXZhbHVlLUFBQSIsImF1dGhvcml0aWVzIjpbImFkbWluIl0sImp0aSI6IjI0NDQ4NGYzLThmZTMtNDU1NS05OTY3LWU3OTI4YjhkYmI3NyIsImp3dC1rZXktYmJiIjoiand0LXZhbHVlLUJCQiIsImNsaWVudF9pZCI6ImFkbWluIiwiand0LWtleS1jY2MiOiJqd3QtdmFsdWUtQ0NDIn0.U9Oy3njtxw0n6cjNUzEKMaRC4aSEQx86Ej-RPPLcmu0",
"token_type": "bearer",
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbImFsbCJdLCJhdGkiOiIyNDQ0ODRmMy04ZmUzLTQ1NTUtOTk2Ny1lNzkyOGI4ZGJiNzciLCJleHAiOjE2MDM5ODc2NTAsImp3dC1rZXktYWFhIjoiand0LXZhbHVlLUFBQSIsImF1dGhvcml0aWVzIjpbImFkbWluIl0sImp0aSI6IjMyNDY5YzgxLTAzNjYtNGRkNC05N2E2LTc0YzdlNDk4MDQ2ZCIsImp3dC1rZXktYmJiIjoiand0LXZhbHVlLUJCQiIsImNsaWVudF9pZCI6ImFkbWluIiwiand0LWtleS1jY2MiOiJqd3QtdmFsdWUtQ0NDIn0.1KrYp0xXuZJJgV2Nkvl3wGrWGTNw7YIMjSnX4_3fdBk",
"expires_in": 43199,
"scope": "all",
"jwt-key-aaa": "jwt-value-AAA",
"jwt-key-bbb": "jwt-value-BBB",
"jwt-key-ccc": "jwt-value-CCC",
"jti": "244484f3-8fe3-4555-9967-e7928b8dbb77"
}

以上面的刷新的令牌重新写入请求参数:

就可以以这个刷新令牌重新获得令牌:

{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbImFsbCJdLCJleHAiOjE2MDE0MzkwNDcsImp3dC1rZXktYWFhIjoiand0LXZhbHVlLUFBQSIsImF1dGhvcml0aWVzIjpbImFkbWluIl0sImp0aSI6ImFmZjBlYTk0LTQ2YTctNDNmZi1iMTQzLTk3NmEzZmRkY2MxMyIsImp3dC1rZXktYmJiIjoiand0LXZhbHVlLUJCQiIsImNsaWVudF9pZCI6ImFkbWluIiwiand0LWtleS1jY2MiOiJqd3QtdmFsdWUtQ0NDIn0.ZA2tiTaJpKcnAMdKnVRH2M5zylb2DRTQGs7wYIXeQZE",
"token_type": "bearer",
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbImFsbCJdLCJhdGkiOiJhZmYwZWE5NC00NmE3LTQzZmYtYjE0My05NzZhM2ZkZGNjMTMiLCJleHAiOjE2MDM5ODc2NTAsImp3dC1rZXktYWFhIjoiand0LXZhbHVlLUFBQSIsImF1dGhvcml0aWVzIjpbImFkbWluIl0sImp0aSI6IjMyNDY5YzgxLTAzNjYtNGRkNC05N2E2LTc0YzdlNDk4MDQ2ZCIsImp3dC1rZXktYmJiIjoiand0LXZhbHVlLUJCQiIsImNsaWVudF9pZCI6ImFkbWluIiwiand0LWtleS1jY2MiOiJqd3QtdmFsdWUtQ0NDIn0.WJVF6_hSTDhKCAzIdX31BppArv6pYkHTOcymbEF5sBU",
"expires_in": 43199,
"scope": "all",
"jwt-key-aaa": "jwt-value-AAA",
"jwt-key-bbb": "jwt-value-BBB",
"jwt-key-ccc": "jwt-value-CCC",
"jti": "aff0ea94-46a7-43ff-b143-976a3fddcc13"
}

【Spring-Security】Re13 Oauth2协议P3 整合JWT的更多相关文章

  1. security和oauth2.0的整合

    security和oauth2.0的整合 之前已经介绍过security的相关的介绍,现在所需要做的就是security和oauth2.0的整合,在原有的基础上我们加上一些相关的代码;代码实现如下: ...

  2. Spring Security实现OAuth2.0授权服务 - 基础版

    一.OAuth2.0协议 1.OAuth2.0概述 OAuth2.0是一个关于授权的开放网络协议. 该协议在第三方应用与服务提供平台之间设置了一个授权层.第三方应用需要服务资源时,并不是直接使用用户帐 ...

  3. Spring Security 与 OAuth2 介绍

    个人 OAuth2 全部文章 Spring Security 与 OAuth2(介绍):https://www.jianshu.com/p/68f22f9a00ee Spring Security 与 ...

  4. Spring Security 与 OAuth2(介绍)

    https://www.jianshu.com/p/68f22f9a00ee Spring Security 与 OAuth2(介绍) 林塬 2018.01.23 11:14* 字数 3097 阅读 ...

  5. [权限管理系统(四)]-spring boot +spring security短信认证+redis整合

    [权限管理系统]spring boot +spring security短信认证+redis整合   现在主流的登录方式主要有 3 种:账号密码登录.短信验证码登录和第三方授权登录,前面一节Sprin ...

  6. Spring Security实现OAuth2.0授权服务 - 进阶版

    <Spring Security实现OAuth2.0授权服务 - 基础版>介绍了如何使用Spring Security实现OAuth2.0授权和资源保护,但是使用的都是Spring Sec ...

  7. Spring Security基于Oauth2的SSO单点登录怎样做?一个注解搞定

    一.说明 单点登录顾名思义就是在多个应用系统中,只需要登录一次,就可以访问其他相互信任的应用系统,免除多次登录的烦恼.本文主要介绍 同域 和 跨域 两种不同场景单点登录的实现原理,并使用 Spring ...

  8. spring boot:spring security实现oauth2+jwt管理认证授权及oauth2返回结果格式化(spring boot 2.3.3)

    一,为什么oauth2要整合jwt? 1,OAuth2的token技术有一个最大的问题是不携带用户信息,所以资源服务器不能进行本地验证, 以致每次对于资源的访问,资源服务器都需要向认证服务器的toke ...

  9. Spring Boot,Spring Security实现OAuth2 + JWT认证

    阅读此文,希望是对JWT以及OAuth2有一定了解的童鞋. JWT认证,提供了对称加密以及非对称的实现. 内容源码点我 涉及到源码中两个服务 spring-boot-oauth-jwt-server ...

  10. spring security和java web token整合

    思路: spring security 1.用户输入用户名密码. 2.验证:从库中(可以是内存.数据库等)查询该用户的密码.角色,验证用户名和密码是否正确.如果正确,则将填充Authenticatio ...

随机推荐

  1. Python 潮流周刊#54:ChatTTS 强大的文本生成语音模型

    本周刊由 Python猫 出品,精心筛选国内外的 250+ 信息源,为你挑选最值得分享的文章.教程.开源项目.软件工具.播客和视频.热门话题等内容.愿景:帮助所有读者精进 Python 技术,并增长职 ...

  2. cent browser 百分浏览器不能使用剪切板复制粘贴

    cent browser 百分浏览器不能使用剪切板复制粘贴,查看剪切板的文本和图像. 解决方法: 1.进入设置-隐私设置和安全性-网站设置 2.查看各网站的权限及储存的数据 3.搜索你的网站,点击重置 ...

  3. ColorEasyDuino上手指南

    介绍 ColorEasyDuino是嘉立创推出的一块Aduino开发板(类似物),具有丰富的外设接口:uart.i2c.spi.adc.pwm等:开发板设计参考原型是Arduino Uno,采用的芯片 ...

  4. 在线Bcrypt加密、验证工具

    在线bcrypt加密,bcrypt算法是一种密码哈希算法,它是基于Blowfish加密算法改进的,能够生成安全性很高的哈希值,并且可以通过调整计算时间来提高安全性.本工具支持在线Bcrypt加密及验证 ...

  5. 我所关注的几个spring设计模式

    Spring框架中实现了许多的设计模式,而且都是非常优先的实现,这些值得我们学好好习. 不过话说回来,我觉得自己只要关注几个即可: 单例 工厂 代理 适配器 观察者 委派 在各种设计模式中,适配器和装 ...

  6. 日志之log4j2和springboot

    log4j2比logback好用. 现在之所有以spring采用logback,根据我个人的理解应该是某种非常特殊的理由.否则log4j2的性能比logback更好,且异步性能极好! 异步日志是log ...

  7. LLM技术全景图:技术人必备的技术指南,一张图带你掌握从基础设施到AI应用的全面梳理

    LLM技术全景图:技术人必备的技术指南,一张图带你掌握从基础设施到AI应用的全面梳理 LLM 技术图谱(LLM Tech Map)是将 LLM 相关技术进行系统化和图形化的呈现,此图谱主要特点是&qu ...

  8. 【主流技术】聊一聊消息队列 RocketMQ 的基本结构与概念

    目录 前言 一.初识 RocketMQ 1.1基本模型 二.基本概念 2.1Producer 2.2Consumer 2.3Topic 2.4Tag 2.5Message 2.6Broker 2.7P ...

  9. 攻防世界——Misc新手练习区解题总结<4>(11、12题)

    第十一题ext3: 方法一:挂载 需要工具:kali虚拟机 下载附件后得到一个linux的系统光盘,我们用kali挂载一下 mount 123 /mnt//123为要挂载的文件名 寻找flag.txt ...

  10. Spring注解之参数校验@Validated和@Valid

    @Validated和@Valid的区别 Spring Validation验证框架对参数的验证机制提供了@Validated(Spring's JSR-303 规范,是标准 JSR-303 的一个变 ...