Skip to content

Safety measures

Compare
Choose a tag to compare
@WalshyDev WalshyDev released this 27 Feb 20:52
· 11 commits to master since this release

This release pushes some safety measures which can be used to better verify the sender of the WebHook. This introduces two new methods to Event, getAuthorization() and getIP(). getAuthorization() is to get the Authorization header (null if it doesn't have one) and getIP() is to return the IP which sent the request.

Usage:

public void onWebHookReceive(WebHookReceiveEvent e){
    if (e.getAuthorization() != null && e.getAuthorization().equals("secretKey1337")) {
        LoggerFactory.getLogger(Example.class).info(String.format("Received webhook from %s, data: %s",
                e.getSender().toString(), e.getPayload().toString()));
    } else
        LoggerFactory.getLogger(Example.class)
                .warn(String.format("Received webhook with invalid authorization from %s pretending to be %s",
                        e.getIP(), e.getSender().toString()));
}