Java Cliente JWT

cliente jwt

Dependencia

<dependency>
		<groupId>org.apache.httpcomponents</groupId>
		<artifactId>httpclient</artifactId>
		<version>4.5.10</version>
	</dependency>

mediante post y los parametros obtiene el JWT del usuario.

private void sendPost() throws Exception {

        HttpPost post = new HttpPost("http://localhost:8080/jwt-provider/auth");

        // add request parameter, form parameters
        List<NameValuePair> urlParameters = new ArrayList<>();
        urlParameters.add(new BasicNameValuePair("username", "user1"));
        urlParameters.add(new BasicNameValuePair("password", "user1"));
        urlParameters.add(new BasicNameValuePair("issuer", "http://apuntesdejava.com"));
        urlParameters.add(new BasicNameValuePair("public-key", "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAprklfylWG4UCFvI4TIXsHB3dZlig1zlsOZWqEqrD3T9dV+PA5XKqL3sujpAiXRZM2fR7Qc8V9VcnuRvph+ihNs77imIKAH29+gPoB4Aq48iiUPWU5B7AzmJqLVgdYMuzYPy1emfXyk2oYXoHnc+6eGJSHidb5KqnM3e662ZTDTahXAS1cQKvYXqGxExaI+DSHEwTglGN+n4suUkW4Vt0KOYkN0gFPCf4wKbXZZfiosF59cjAQ/YVE2EwXQ8KCDGpTh3Uy4vkz+wX3cmEOAzPU0SddFXr3u5Zm3xf1BCC1EqLsGqbx2vOOeBNW4lOrRX2HpgBjM+ZYS0ZjtOwC+tc/QIDAQAB"));

        post.setEntity(new UrlEncodedFormEntity(urlParameters));

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
                CloseableHttpResponse response = httpClient.execute(post)) {
            String txt = EntityUtils.toString(response.getEntity());
            System.out.println("---------------------------");
            System.out.println("EL JWT es");
            System.out.println(txt);
            System.out.println("---------------------------");
            System.out.println(EntityUtils.toString(response.getEntity()));
        }

    }

Last updated