title: invalid_token:Cannot convert access token to JSON
body: <p>I get error while refreshing the token(grant_type=refresh_token). It seems that user did not use the application for long time and both access token as well as refresh token expired. When app now tried to refresh token, it gets the error</p>
  
  <blockquote>
  <pre><code>{
  "error": "invalid_token",
  "error_description": "Cannot convert access token to JSON" 
    }
  </code></pre>
  </blockquote>
  
  <p>I saw many posts on this issue but I am still facing this error. I tried to use setVerifierKey. But no luck. Here is the code:</p>
  
  <pre><code>@Configuration
     @EnableWebSecurity
     @EnableGlobalMethodSecurity(prePostEnabled = true)
     public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
  @Value("${security.signing-key}")
  private String signingKey;
  
  @Value("${security.encoding-strength}")
  private Integer encodingStrength;
  
  @Value("${security.security-realm}")
  private String securityRealm;
  
  @Autowired
  private UserDetailsService userDetailsService;
  
  @Bean
  @Override
  protected AuthenticationManager authenticationManager() throws Exception {
      return super.authenticationManager();
  }
  
  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.userDetailsService(userDetailsService);
            //  .passwordEncoder(new ShaPasswordEncoder(encodingStrength));
  }
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
      http
              .sessionManagement()
              .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
              .and()
              .httpBasic()
              .realmName(securityRealm)
              .and()
              .csrf()
              .disable();
  
  }
  
  @Bean
  public JwtAccessTokenConverter accessTokenConverter() {
      JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
      converter.setSigningKey(signingKey);
      return converter;
  }
  
  @Bean
  public TokenStore tokenStore() {
      return new JwtTokenStore(accessTokenConverter());
  }
  
  @Bean
  @Primary //Making this primary to avoid any accidental duplication with another token service instance of the same name
  public DefaultTokenServices tokenServices() {
      DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
      defaultTokenServices.setTokenStore(tokenStore());
      defaultTokenServices.setSupportRefreshToken(true);
      return defaultTokenServices;
  }
  }
  
  
  
  //AuthorizationServerConfig
  
  @Configuration
  @EnableAuthorizationServer
  public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
  
  @Value("${security.jwt.client-id}")
  private String clientId;
  
  @Value("${security.jwt.client-secret}")
  private String clientSecret;
  
  @Value("${security.jwt.grant-type}")
  private String grantType;
  
  @Value("${security.jwt.scope-read}")
  private String scopeRead;
  
  @Value("${security.jwt.scope-write}")
  private String scopeWrite = "write";
  
  @Value("${security.jwt.resource-ids}")
  private String resourceIds;
  
  @Autowired
  private TokenStore tokenStore;
  
  @Autowired
  private JwtAccessTokenConverter accessTokenConverter;
  
  @Autowired
  private AuthenticationManager authenticationManager;
  @Autowired
  private UserDetailsService userDetailsService;
  
  @Override
  public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
      configurer
              .inMemory()
              .withClient(clientId)
              .secret(clientSecret)
              .authorizedGrantTypes("client_credentials", "password", "refresh_token", "authorization_code")
              .scopes(scopeRead, scopeWrite)
             // .accessTokenValiditySeconds(60)
             // .refreshTokenValiditySeconds(2000)
              .resourceIds(resourceIds);
  }
  
  @Override
  public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
      TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
      enhancerChain.setTokenEnhancers(Arrays.asList(accessTokenConverter));
      endpoints.tokenStore(tokenStore)
              .accessTokenConverter(accessTokenConverter)
              .tokenEnhancer(enhancerChain).userDetailsService(userDetailsService)
              .authenticationManager(authenticationManager);
  }
  
  }
  </code></pre>
  
  <p>I expect that token will be refreshed but I get the error as mentioned above.  my config properties are:</p>
  
  <ul>
  <li>security.oauth2.resource.filter-order=3   </li>
  <li>security.signing-key=ZMaasazkSjmaasw </li>
  <li>security.encoding-strength=256 </li>
  <li>security.security-realm=Spring Boot JWT Example Realm      </li>
  <li>security.jwt.grant-type=password security.jwt.scope-read=read   </li>
  <li>security.jwt.scope-write=write   </li>
  <li>security.jwt.resource-ids=testjwtresourceid</li>
  </ul>
  
  <p>Any Help appreciated!!</p>