1.添加jwt依赖

pom.xml

		<!-- jwt依赖 -->
		<dependency>
			<groupId>io.jsonwebtoken</groupId>
			<artifactId>jjwt</artifactId>
			<version>0.9.0</version>
		</dependency>

2.使用jwt依赖进行解析,获取jwt内容

UserController.java

/**
 * @author etern
 * @title: UserController
 * @projectName springsecurityoauth2-demo
 * @description: TODO
 * @date 2022/2/17 19:56
 */
@RestController
@RequestMapping("/user")
public class UserController {
	/**
	 * @return { java.lang.Object}
	 * @throws
	 * @Author etern
	 * @Description TODO 获取当前用户
	 * @Date 20:04 2022/2/17
	 * @Param * @param authentication
	 **/
	@RequestMapping("/getCurrentUser")
	public Object getCurrentUser(Authentication authentication, HttpServletRequest request) {
		String head = request.getHeader("Authorization");
		String token = head.substring(head.indexOf("bearer") + 7);
		// 使用jwt依赖进行解析,获取jwt内容
		return Jwts.parser()
				// 对应的秘钥,设定UTF-8的形式
				.setSigningKey("test_key".getBytes(StandardCharsets.UTF_8))
				.parseClaimsJws(token)
				.getBody();
	}
}