title: Spring boot OAUTH2 cannot refresh_token - UserDetailService is required
body: <p>I'm using Spring Boot version 1.4.3.RELEASE and trying to set up my Authorization Server.</p>
  
  <p>I have no problem when creating the token or accessing the resources when the access_token is valid, but when it expires and I try to refresh it, i'm getting an error</p>
  
  <pre><code>{
    "error": "server_error",
    "error_description": "UserDetailsService is required."
  }
  </code></pre>
  
  <p>This is the request i make to refresh the access_token</p>
  
  <pre><code>http://localhost:11134/oauth/token?grant_type=refresh_token&amp;refresh_token=0d17dfee-1185-480d-af30-ba0f1e47831c&amp;scope=read
  </code></pre>
  
  <p>refresh_token is correct</p>
  
  <p>This is my AuthorizationServer</p>
  
  <pre><code>protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter implements EnvironmentAware {
  
              private static final String ENV_OAUTH = "security.oauth2.client.";
              private static final String PROP_CLIENTID = "client-id";
              private static final String PROP_SECRET = "client-secret";
              private static final String PROP_TOKEN_VALIDITY_SECONDS = "access-token-validity-seconds";
              private static final String PROP_REFRESH_TOKEN_VALIDITY_SECONDS = "refresh-token-validity-seconds";
  
  
              private RelaxedPropertyResolver propertyResolver;
  
  
  
              @Autowired
              private DataSource dataSource;
  
              @Bean
              public TokenStore tokenStore() {
                  return new JdbcTokenStore(dataSource);
              }
              @Autowired
              private CustomUserDetailsService userDetailsService;
  
              @Autowired
              @Qualifier("authenticationManagerBean")
              private AuthenticationManager authenticationManager;
  
              @Override
              public void configure(AuthorizationServerEndpointsConfigurer endpoints)
                      throws Exception {
                  endpoints
                          .tokenStore(tokenStore())
                          .authenticationManager(authenticationManager).userDetailsService(userDetailsService);
              }
  
              @Override
              public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
                  clients
                          .inMemory()
                          .withClient(propertyResolver.getProperty(PROP_CLIENTID))
                          .scopes("read", "write", "trust")
                          .authorities(Authorities.ROLE_ADMIN.name(), Authorities.ROLE_USER.name())
                          .authorizedGrantTypes("password", "refresh_token")
                          .secret(propertyResolver.getProperty(PROP_SECRET))
                          .accessTokenValiditySeconds(propertyResolver.getProperty(PROP_TOKEN_VALIDITY_SECONDS, Integer.class))
                          .refreshTokenValiditySeconds(propertyResolver.getProperty(PROP_REFRESH_TOKEN_VALIDITY_SECONDS, Integer.class));
              }
  
              public void setEnvironment(Environment environment) {
                  this.propertyResolver = new RelaxedPropertyResolver(environment, ENV_OAUTH);
              }
  
  
          }
  </code></pre>
  
  <p>Then this is WebSecurityConfiguration</p>
  
  <pre><code>@Configuration
       @EnableWebSecurity
  //   @EnableGlobalMethodSecurity(prePostEnabled = true, jsr250Enabled = true)
  
       public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
       @Autowired
          private UserDetailsService userDetailsService;
  
          @Bean
          public PasswordEncoder passwordEncoder() {
              return new StandardPasswordEncoder();
          }
  
          @Autowired
          public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  
              auth
                      .userDetailsService(userDetailsService)
                      .passwordEncoder(passwordEncoder());
  
  
  
          }
   @Override
          @Bean
          public AuthenticationManager authenticationManagerBean() throws Exception {
              return super.authenticationManagerBean();
          }
  
  
          }
  </code></pre>
  
  <p>if it's interesting, this is <code>CustomUserDetailService</code></p>
  
  <pre><code>@Component("userDetailsService")
  public class CustomUserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService {
  
      private final Logger log = LoggerFactory.getLogger(UserDetailsService.class);
  
      @Autowired
      private UserRepository userRepository;
  
      @Override
      @Transactional
      public UserDetails loadUserByUsername(final String login) {
  
          log.debug("Authenticating {}", login);
          String lowercaseLogin = login.toLowerCase();
  
          User userFromDatabase;
              userFromDatabase = userRepository.findByUsernameCaseInsensitive(lowercaseLogin);
  
  
  
          Collection&lt;GrantedAuthority&gt; grantedAuthorities = new ArrayList&lt;&gt;();
          for (Authority authority : userFromDatabase.getAuthorities()) {
              GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(authority.getName());
              grantedAuthorities.add(grantedAuthority);
          }
  
          return new org.springframework.security.core.userdetails.User(userFromDatabase.getUsername(), userFromDatabase.getPassword(), grantedAuthorities);
  
      }
  
  }
  </code></pre>