title: How to get the authorization code from query params // Amazon Cognito authorization endpoint
body: <p>I am trying to hit cognito authorization URL on a jsp load. When the JSP gets called, I call a java method in my jsp. Following is the code snippet:</p>
  <pre><code>public static void getData(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setStatus(HttpServletResponse.SC_FOUND);
      response.setHeader(&quot;Location&quot;,
              &quot;https://test.us-west-2.amazoncognito.com/oauth2/authorize?redirect_uri=https://test.com&amp;client_id=123456789&amp;response_type=code&quot;);
  }
  </code></pre>
  <p>The users successfully gets redirected when they hit the jsp. The authorization code <code>code</code> is appended to the url (I can see in the tomcat logs).</p>
  <p>I need the authorization code in my method. I have tried getting it from request <code>request.getParameter(&quot;code&quot;);</code>, but that didn't work.</p>
  <p>How do I get the code? Its appended to the url as a query param.</p>
  <blockquote>
  <p>user [14/Jul/2021:15:35:43 -0400] &quot;GET
  /app?code=fdsfs-fsd-4324-4324-fdsfsdfjh5u34 HTTP/1.1&quot; 302 - 6553</p>
  </blockquote>