title: Spring Boot 2.0 OAuth2 Client - Getting bearer token across sessions
body: <p>I have a basic OAuth2 App set up:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  @EnableOAuth2Sso
  @Order(0)
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      public void configure(HttpSecurity http) throws Exception {
          http.csrf().disable().authorizeRequests()
                  .antMatchers("/actuator/health", "/", "/noauth", "/login").permitAll()
                  .anyRequest().authenticated().and()
                  .oauth2Login().defaultSuccessUrl("/auth");
      }
  }
  </code></pre>
  
  <p>It works well for a single instance and I can request <code>OAuth2AuthorizedClient</code> details:</p>
  
  <pre class="lang-java prettyprint-override"><code>Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  OAuth2AuthenticationToken oauthToken = (OAuth2AuthenticationToken) authentication;
  OAuth2AuthorizedClient client = clientService.loadAuthorizedClient(
      oauthToken.getAuthorizedClientRegistrationId(), oauthToken.getName());
  
  // Gets an OAuth2 token
  client.getAccessToken().getTokenValue()
  </code></pre>
  
  <p>However, if I run this in a microservices environment (>1 instance) then <code>client</code> will always be null. Authentication also doesn't work correctly in this case.</p>
  
  <p>I am using the <code>org.springframework.security:spring-security-oauth2-jose</code> library and authenticating with Google.</p>
  
  <p>Any hints on how to persist the bearer token between sessions (or refresh it if it's not there)?</p>