title: How to extract authentication token in @Controller
body: <p>I have Spring Boot app that uses OAuth 2.0 and Authorization Server. When I try to access a secured page, I get a redirect to the login page of my authorization server (Blitz Identity Provider) and everything works like it should.</p>
  <p>My problem is that <em>I can't extract authorization token in <code>@Controller</code> (on the secured page)</em>. That token I want to use later to authorize in second application.</p>
  <ul>
  <li>Tried <a href="https://stackoverflow.com/questions/27864295/how-to-use-oauth2resttemplate">this thing</a> (in answer) and it worked, I got my token back,
  but as you can see, it's a hardcode of username and password
  parameters and it's like login over login -- I don't need to login
  for a second time (on authenticated page).</li>
  <li>Tried to output <em>authentication.getDetails()</em>, it shows token type
  and token like <em>&lt; TOKEN &gt;</em>, but it's not enough.</li>
  <li>Tried to lookup token in request-response headers, but didn't find
  it, so authorization server doesn't send it in headers.</li>
  </ul>
  <p>Here are 2 files which can help you to understand some part of my context.</p>
  <p><em>application.yml</em></p>
  <pre><code>server:
    port: 8080
    context-path: /
    session:
      cookie:
        name:FIRSTSESSION
  security:
    basic:
      enabled: false
    oauth2:
      client:
        clientId: test_id
        clientSecret: f3M5m9a2Dn0v15l
        accessTokenUri: http://server:9000/blitz/oauth/te
        userAuthorizationUri: http://server:9000/blitz/oauth/ae?scope=test_scope
      resource:
        userInfoUri: http://server:9000/blitz/oauth/me
  logging:
    level:
      org.springframework.security: DEBUG
  </code></pre>
  <p><em>SsoController.java</em></p>
  <pre><code>@EnableOAuth2Sso
  @Controller
  public class SsoController {
  
      @RequestMapping(&quot;/secondService&quot;)
      public String getContent(HttpServletRequest request, Model model) {
  
          Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
          model.addAttribute(&quot;submittedValue&quot;, authentication.getDetails());
          return &quot;secondService&quot;;
      } 
  }
  </code></pre>
  <p>So, what you can suggest? How can I extract authorization token in this case?</p>