Spring boot 如何使用已有的访问令牌创建Jwt

Spring boot 如何使用已有的访问令牌创建Jwt,spring-boot,jwt,access-token,spring-boot-test,Spring Boot,Jwt,Access Token,Spring Boot Test,我正在尝试为我的SpringBoot应用程序创建JUnit测试 测试的目的是检查给定令牌的授权。 我检索令牌(从一个远程API(Auth0)),但我无法用它填充/实例化JWT对象(以便用它测试我的CustomJwtAuthenticationConverter.java) 在我的Junit测试中,我执行一个HTTPPOST请求,并且在响应的主体中有access_令牌 是否可以获取令牌字符串并使用它创建有效的Jwt实例 import org.springframework.security.oau

我正在尝试为我的SpringBoot应用程序创建JUnit测试

测试的目的是检查给定令牌的授权。 我检索令牌(从一个远程API(Auth0)),但我无法用它填充/实例化JWT对象(以便用它测试我的CustomJwtAuthenticationConverter.java)

在我的Junit测试中,我执行一个HTTPPOST请求,并且在响应的主体中有access_令牌

是否可以获取令牌字符串并使用它创建有效的Jwt实例

import org.springframework.security.oauth2.jwt.Jwt;

[...]

private Collection<? extends GrantedAuthority> extractResourceRoles(final Jwt jwt) {
   boolean authorityGranted = true;
   // Check token's paylaod values
   List<String> audiences = jwt.getClaim("theClaim");

   [...]

   if(authorityGranted) {
       return authority.stream()
               .map(SimpleGrantedAuthority::new)
               .collect(Collectors.toSet());
   } else {
       return Collections.emptySet();
   }
}
import org.springframework.security.oauth2.jwt.jwt;
[...]

私人收藏能否添加您的
CustomJwtAuthenticationConverter
以了解它需要什么
Jwt
对象?最后,每个JWT都只是一个字符串,作为HTTP授权头的一部分