title: Spring Boot Oauth 2.0 Authorization Server returning null token
body: <p>I'm trying to understand Oauth 2.0 and i've tried to follow a simple tutorial but i don't understand what's wrong with my code.Basically the authorization server is not returning any token to the client and i don't understand why:(
  Here is the code:
  ResourceServer App:
  AuthorizationServerConfig:</p>
  
  <pre><code>@Configuration
  @EnableAuthorizationServer
  public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
  
      @Override
      public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
          clients.inMemory().withClient("javainuse").secret("secret").authorizedGrantTypes("authorization_code")
              .scopes("read").authorities("CLIENT").redirectUris("http://localhost:8090/showEmployees");
      }
  
  }
  </code></pre>
  
  <p>EmployeeSecurityConfiguration:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class EmployeeSecurityConfiguration extends WebSecurityConfigurerAdapter {
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web.ignoring().antMatchers("/resources/**");
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/user/getEmployeesList").hasAnyRole("ADMIN")
                  .anyRequest().authenticated().and().formLogin().permitAll().and().logout().permitAll();
  
          http.csrf().disable();
      }
  
      @Override
      public void configure(AuthenticationManagerBuilder authenticationMgr) throws Exception {
          authenticationMgr.inMemoryAuthentication().passwordEncoder(NoOpPasswordEncoder.getInstance()).withUser("admin").password("admin").authorities("ROLE_ADMIN");
      }
  }
  </code></pre>
  
  <p>ResourceServer:</p>
  
  <pre><code>@Configuration
  @EnableResourceServer
  public class ResourceServer extends ResourceServerConfigurerAdapter {
  
      @Override
      public void configure(HttpSecurity http) throws Exception {
          http.requestMatchers().antMatchers("/user/getEmployeesList/**").and().authorizeRequests().anyRequest()
                  .access("#oauth2.hasScope('read')");
      }
  }
  </code></pre>
  
  <p>EmployeeController:</p>
  
  <pre><code>@Controller
  public class EmployeeController {
  
      @RequestMapping(value = "/user/getEmployeesList", produces ="application/json")
      @ResponseBody
      public List&lt;Employee&gt; getEmployeeList(){
          List&lt;Employee&gt; employees = new ArrayList&lt;&gt;();
          Employee emp = new Employee();
          emp.setEmpId("emp1");
          emp.setEmpName("emp1");
          employees.add(emp);
          return employees;
      }
  
  }
  </code></pre>
  
  <p>And the client app:</p>
  
  <pre><code>@Controller
  public class EmployeeController {
  
      @RequestMapping(value = "/getEmployees", method = RequestMethod.GET)
      public ModelAndView getEmployeeInfo() {
          return new ModelAndView("getEmployees");
      }
  
      @RequestMapping(value = "/showEmployees", method = RequestMethod.GET)
      public ModelAndView showEmployees(@RequestParam("code") String code) throws JsonProcessingException, IOException {
          ResponseEntity&lt;String&gt; response = null;
          System.out.println("Authorization Code------" + code);
  
          RestTemplate restTemplate = new RestTemplate();
  
          // According OAuth documentation we need to send the client id and secret key in the header for authentication
          String credentials = "javainuse:secret";
          String encodedCredentials = new String(Base64.encodeBase64(credentials.getBytes()));
  
          HttpHeaders headers = new HttpHeaders();
          headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
          headers.add("Authorization", "Basic " + encodedCredentials);
  
          HttpEntity&lt;String&gt; request = new HttpEntity&lt;String&gt;(headers);
  
          String access_token_url = "http://localhost:8080/oauth/token";
          access_token_url += "?code=" + code;
          access_token_url += "&amp;grant_type=authorization_code";
          access_token_url += "&amp;redirect_uri=http://localhost:8090/showEmployees";
  
          response = restTemplate.exchange(access_token_url, HttpMethod.POST, request, String.class);
  
          System.out.println("Access Token Response ---------" + response.getBody());
          return null;
  
      }
  }
  </code></pre>
  
  <p>The sysout that shows the response.getBody() is always null and i have no clue why it's that happening</p>