Skip to content

Cosium/standard-webhooks-consumer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Maven Central Version

Standard Webhooks Consumer

https://www.standardwebhooks.com/ consumer side java library.

Maven dependency

<dependency>
  <groupId>com.cosium.standard_webhooks_consumer</groupId>
  <artifactId>standard-webhooks-consumer</artifactId>
  <version>${standard-webhooks-consumer.version}</version>
</dependency>

Signature verification

public class App {

  public void verifySymmetricSignature() throws WebhookSignatureVerificationException {

    WebhookSignatureVerifier verifier =
        WebhookSignatureVerifier.builder("whsec_b6Ovv5eS7H5seJrGSStBYDivs8v2/KrFjfMaVZYsi7w=")
            .build();
    HttpHeaders httpHeaders =
        createHttpHeaders(
            Map.of(
                "webhook-id",
                "7a2486b3-31cf-4bd3-a460-df8845d16cd5",
                "webhook-timestamp",
                String.valueOf(1737987215),
                "webhook-signature",
                "v1,iayM3VaiYCEDP/CxWUFWcxUCJk2YmBDQHtHTsaHzrwo="));
    verifier.verify(httpHeaders, "{\"greetings\": \"Hello World\"}");
  }

  public void verifyAsymmetricSignature() throws WebhookSignatureVerificationException {

    WebhookSignatureVerifier verifier =
        WebhookSignatureVerifier.builder(
                "whpk_MCowBQYDK2VwAyEAkp3dScDPIzT1CwUFUMdzyPbWOAQaCF9z4ucuKuZD7Io=")
            .build();

    HttpHeaders httpHeaders =
        createHttpHeaders(
            Map.of(
                "webhook-id",
                "7a2486b3-31cf-4bd3-a460-df8845d16cd5",
                "webhook-timestamp",
                String.valueOf(1737987215),
                "webhook-signature",
                "v1a,XVbiOe+IzCKsXBuhb52iHLroqxFJofJNMQRL80I2kWO0+kXu2gcqgXAzontxDDgpMDw6SMh4sjzr+67EmUUzDg=="));

    verifier.verify(httpHeaders, "{\"greetings\": \"Hello World\"}");
  }

  private HttpHeaders createHttpHeaders(Map<String, String> headers) {
    return HttpHeaders.of(
        headers.entrySet().stream()
            .map(entry -> Map.entry(entry.getKey(), List.of(entry.getValue())))
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)),
        (s, s2) -> true);
  }
}

About

https://www.standardwebhooks.com/ consumer side java library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy