title: Spring Boot Authorization Server send request to external service to get user details
body: <p>I got a lot of services and I want to centralize my authentication with an authentication-service. Now I am a noobie at Spring boot and I have no clue how do I make this possible.</p>
  
  <p>I just implement the normal security from Spring and it works perfectly and I only find some tutorials about <code>jdbcAuthentication</code>, <code>inMemoryAuthentication</code>, etc but not an authentication where the authentication-service send a request to another service. Does anyone get a clue about this?</p>
  
  <p>My security based on tokens -> <code>JWT</code></p>
  
  <p>I think I need to manipulate the <code>AuthenticationManagerBuilder</code> because it decides whether a username is valid or not. </p>
  
  <pre><code>protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  }
  </code></pre>
  
  <p>and I make my request with Feign - maybe the wrong location for this code</p>
  
  <pre><code>@Override
  public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res) throws AuthenticationException, IOException, ServletException {
      AccountCredentials credentials = new ObjectMapper()
              .readValue(req.getInputStream(), AccountCredentials.class);
  
      UserRequest userRequest = Feign.builder()
              .decoder(new GsonDecoder())
              .target(UserRequest.class,"http://localhost:7998/api/user-service/user/" + credentials.getUsername());
  
      return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken(credentials.getUsername(),credentials.getPassword(),emptyList()));
  }
  </code></pre>