code: private static String federatedFlowStep3(LoginInput loginInput, String tokenUrl)
    throws SnowflakeSQLException
  
    {
      String oneTimeToken = "";
      try
      {
        URL url = new URL(tokenUrl);
        URI tokenUri = url.toURI();
        final HttpPost postRequest = new HttpPost(tokenUri);
  
        StringEntity params = new StringEntity("{\"username\":\"" +
                                               loginInput.getUserName() + "\",\"password\":\"" +
                                               loginInput.getPassword() + "\"}");
        postRequest.setEntity(params);
  
        HeaderGroup headers = new HeaderGroup();
        headers.addHeader(new BasicHeader(HttpHeaders.ACCEPT, "application/json"));
        headers.addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"));
        postRequest.setHeaders(headers.getAllHeaders());
  
        final String idpResponse = HttpUtil.executeRequestWithoutCookies(postRequest,
                                                                         loginInput.getLoginTimeout(), 0, null);
  
        logger.debug("user is authenticated against {}.",
                     loginInput.getAuthenticator());
  
        // session token is in the data field of the returned json response
        final JsonNode jsonNode = mapper.readTree(idpResponse);
        oneTimeToken = jsonNode.get("cookieToken").asText();
      }
      catch (IOException | URISyntaxException ex)
      {
        handleFederatedFlowError(loginInput, ex);
      }
      return oneTimeToken;
    }
docs: Query IDP token url to authenticate and retrieve access token
  
  @param loginInput
  @param tokenUrl
  @return
  @throws SnowflakeSQLException