title: OAuth2 client credentials flow via Spring Boot Keycloak integration
body: <p>My application consists of:</p>
  
  <ul>
  <li>backend/resource server</li>
  <li>UI webapp</li>
  <li>keycloak</li>
  </ul>
  
  <p>The UI is talking with the backend server via RESTful API using the keycloak client with authorization code grant flow. This is working fine.</p>
  
  <p>Now, I need the additional possibility to access resource of the backend using a system/service account (with usually more permissions than the user). How would you implement this requirement? I thought the client credentials flow would be useful here.</p>
  
  <p>Is it possible to use the OAuth2 client credentials flow with the keycloak client for Spring Boot? I found examples that used the Spring Security OAuth2 client features to achieve a client credentials flow but that feels weird because I already use the keycloak client for the OAuth thing.</p>
  
  <h2>Edit: Solution</h2>
  
  <p>Thanks for your answers which helped me a lot. In my UI webapp, I am now able to communicate with the backend either by using the authenticated user OAuth2 token or by using the token from the client credentials flow of my UI service account. Each way has its own <code>RestTemplate</code>, the first is done via the keycloak integration and second is done by Spring Security OAuth2 as explained <a href="https://stackoverflow.com/questions/46073485/keycloak-spring-security-client-credential-grant/46400975#46400975">here</a>.</p>