title: OAuth2 token revocation getting classCastException Converting OAuth2AuthenticationToken to OAuth2Authentication
body: <p>Unable to logout from google account after logging out through web app (Using google authorization for log into my app). When I hit the login URL next time for fresh login, instead of loading the sign in page, my application signed in with the last user credentials.
  When I check various SO Q &amp; A, I found out that I need to revoke the authorization token from token store. Below is the code I have tried:</p>
  <pre><code>    import org.springframework.security.core.Authentication;
      import org.springframework.security.oauth2.provider.token.TokenStore;
      import org.springframework.security.oauth2.common.OAuth2AccessToken;
      import org.springframework.security.oauth2.provider.OAuth2Authentication;
      class LoginController
      {
           @PostMapping(&quot;/logout&quot;)
          public String logout_invoked(Authentication authentication)
              {
                  Optional.ofNullable(authentication).ifPresent(auth -&gt; {
                  OAuth2AccessToken accessToken = tokenStore.getAccessToken((OAuth2Authentication) auth); // classCast exception unable to convert Authentication to OAuth2Authentication
          
                   Optional.ofNullable(accessToken).ifPresent(oAuth2AccessToken -&gt; {
                      Optional.ofNullable(oAuth2AccessToken.getRefreshToken()).ifPresent(tokenStore::removeRefreshToken);
                       tokenStore.removeAccessToken(accessToken);
                       
                   });
               });
             return &quot;logoutPage&quot;;
             }
     }
  </code></pre>
  <blockquote>
  <p>[Request processing failed; nested exception is
  java.lang.ClassCastException: class
  org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken
  cannot be cast to class
  org.springframework.security.oauth2.provider.OAuth2Authentication
  (org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken
  and org.springframework.security.oauth2.provider.OAuth2Authentication
  are in unnamed module of loader 'app')] with root cause</p>
  </blockquote>
  <p>I need to remove authorization token specific to the user who logging out currently.</p>
  <p>P.S</p>
  <p>As a work around, test user needs to sign out from web application followed by google account from browser to avoid same user signing in back.</p>