title: How can I get the OAuth2AccessToken with Spring-Boot?
body: <p>I am using Spring-Boot and Spring Security with an OAuth2 login from a third party.</p>
  
  <p>The SSO provider has an accesstoken end point which returns the following JSON</p>
  
  <pre><code>{
      "access_token": "CGjok",
      "refresh_token": "TSHO6E",
      "scope": "openid profile ",
      "id_token": "eyJ0eXAiOiJKV1QiLCg",
      "token_type": "Bearer",
      "expires_in": 7199,
      "nonce": "ImplicitFlowTest"
  }
  </code></pre>
  
  <p>The login is working with the @EnableOAuth2Sso annotation as follows:</p>
  
  <pre><code>@EnableOAuth2Sso
  @Configuration
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      public void configure(HttpSecurity http) throws Exception {
  
  
          http.authorizeRequests().antMatchers("/restapi/**").hasAuthority("Mitarbeiter")
              .antMatchers("/login", "/static/**", "/", "/actuator/prometheus","/error**","/logout").permitAll()
              .and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).invalidateHttpSession(true)
              .deleteCookies("SMSESSION", "JSESSIONID", "XSRF-TOKEN").logoutSuccessUrl("/");
  
             http
             // CSRF Token
             .csrf()
                 .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
  
      }  
  </code></pre>
  
  <p>We are able to logout of the application but we also want to send a request to the Authorization Server. To do so I need to access the token info endpoint. </p>
  
  <p>Within my controllers I am able to see the Principal is getting the correct information from the user endpoint but where in Spring Boot is the information from the accessToken endpoint stored. I have found the class OAuth2AccessToken but cannot figure out how to read it in Spring Controller. I can access the OAuth2Authentication by casting the Principal as expected. </p>
  
  <p>The SSO authorization server has the following endpoint that I need to call:</p>
  
  <pre><code>/oauth2/connect/endSession?id_token_hint=&lt;oidc-token&gt;&amp;post_logout_redirect_uri=&lt;post-logout-redirect-uri&gt;
  </code></pre>
  
  <p>The  refers to the value in the JSON from the accesstoken endpoint. How can I access these values given my setup?</p>