title: Spring Oauth2 Error "Token not found in request parameters" on entering username and password in custom login page
body: <p>I have created custom login page in spring boot and spring-security-oauth2. On entering username and password getting error as </p>
  
  <p>o.s.s.o.p.a.BearerTokenExtractor         : Token not found in headers. Trying request parameters.
  o.s.s.o.p.a.BearerTokenExtractor         : Token not found in request parameters.  Not an OAuth2 request.
  p.a.OAuth2AuthenticationProcessingFilter : No token in request, will continue chain.
  s.s.o.p.e.DefaultOAuth2ExceptionRenderer : Written [error="unauthorized", error_description="Full authentication is required to access this resource"] as "application/xhtml+xml" using [org.springframework.security.oauth2.http.converter.jaxb.JaxbOAuth2ExceptionMessageConverter@cefdf9] </p>
  
  <p>How to pass token as header parameter any lead?</p>
  
  <pre><code> @Configuration
      @EnableWebSecurity
      @Import(Encoders.class)
      public class ServerSecurityConfig extends WebSecurityConfigurerAdapter {
  
          @Autowired
          private UserDetailsService userDetailsService;
  
          @Autowired
          private PasswordEncoder userPasswordEncoder;
  
          @Override
          @Bean
          public AuthenticationManager authenticationManagerBean() throws Exception {
              return super.authenticationManagerBean();
          }
  
          @Override
          protected void configure(AuthenticationManagerBuilder auth) throws Exception {
              auth.userDetailsService(userDetailsService).passwordEncoder(userPasswordEncoder);
          }
  
          @Override
          @Order(Ordered.HIGHEST_PRECEDENCE)
          protected void configure(HttpSecurity http) throws Exception {
              http
              .sessionManagement()
              .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
              .and()
              .csrf().disable()
              .authorizeRequests()
              .antMatchers("/resources/**").permitAll()
              .antMatchers("/about").permitAll() 
              .antMatchers("/oauth/token").permitAll()
              .and()
              .httpBasic()
              .and()
              .formLogin()
              .loginPage("/login")
              .loginProcessingUrl("/loginSecure")
              .defaultSuccessUrl("/index", true)
              .permitAll();
              }
  }
  </code></pre>
  
  <p>and ResourceServer</p>
  
  <pre><code>    @Configuration
      @EnableResourceServer
      public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
  
          private static final String RESOURCE_ID = "resource-server-rest-api";
          private static final String SECURED_READ_SCOPE = "#oauth2.hasScope('read')";
          private static final String SECURED_WRITE_SCOPE = "#oauth2.hasScope('write')";
          private static final String SECURED_PATTERN = "/secured/**";
  
          @Override
          public void configure(ResourceServerSecurityConfigurer resources) {
              resources.resourceId(RESOURCE_ID);
          }
  
          @Override
          @Order(Ordered.HIGHEST_PRECEDENCE)
          public void configure(HttpSecurity http) throws Exception {
              http.authorizeRequests().antMatchers("/login", "/resources/**/**","/resources/").permitAll()
              .and().requestMatchers()
                      .antMatchers("/loginSecure", SECURED_PATTERN).and().authorizeRequests()
                      .antMatchers("/loginSecure", SECURED_PATTERN).access(SECURED_WRITE_SCOPE)
                      .anyRequest().access(SECURED_READ_SCOPE)
                      .and().csrf().disable();
  
          }
  }
  </code></pre>
  
  <p>AuthorizationServerConfigurerAdapter  class:</p>
  
  <pre><code>@Configuration
  @EnableAuthorizationServer
  @EnableGlobalMethodSecurity(prePostEnabled = true)
  @Import(ServerSecurityConfig.class)
  public class AuthServerOAuth2Config extends AuthorizationServerConfigurerAdapter {
      @Autowired
      @Qualifier("dataSource")
      private DataSource dataSource;
  
      @Autowired
      private AuthenticationManager authenticationManager;
  
      @Autowired
      private UserDetailsService userDetailsService;
  
      @Autowired
      private PasswordEncoder oauthClientPasswordEncoder;
  
      @Bean
      public TokenStore tokenStore() {
          return new JdbcTokenStore(dataSource);
      }
  
      @Bean
      public OAuth2AccessDeniedHandler oauthAccessDeniedHandler() {
          return new OAuth2AccessDeniedHandler();
      }
  
      @Override
      public void configure(AuthorizationServerSecurityConfigurer oauthServer) {
          oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()").passwordEncoder(oauthClientPasswordEncoder);
      }
  
      @Override
      public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
          clients.jdbc(dataSource);
      }
  
      @Override
      public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
          endpoints.tokenStore(tokenStore()).authenticationManager(authenticationManager).userDetailsService(userDetailsService);
      }
  }
  </code></pre>