return;
}
HttpClient client = getVertx().createHttpClient().setSSL(true).setHost("verifier.login.persona.org").setPort(443);
HttpClientRequest clientRequest = client.post("/verify", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse response) {
// error handler
response.exceptionHandler(new Handler<Throwable>() {
@Override
public void handle(Throwable err) {
next.handle(err);
}
});
final Buffer body = new Buffer(0);
// body handler
response.dataHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
body.appendBuffer(buffer);
}
});
// done
response.endHandler(new Handler<Void>() {
@Override
public void handle(Void event) {
try {
JsonObject verifierResp = new JsonObject(body.toString());
boolean valid = "okay".equals(verifierResp.getString("status"));
String email = valid ? verifierResp.getString("email") : null;
// assertion is valid:
if (valid) {
// generate a session
request.createSession();
// OK response
request.response().end(new JsonObject().putBoolean("success", true));
} else {
request.response().end(new JsonObject().putBoolean("success", false));
}
} catch (DecodeException ex) {
// bogus response from verifier!
request.response().end(new JsonObject().putBoolean("success", false));
}
}
});
}
});
clientRequest.putHeader("content-type", "application/x-www-form-urlencoded");
clientRequest.putHeader("content-length", Integer.toString(data.length()));
clientRequest.end(data);
}
})
);
yoke.listen(8080);