Menu AuthGuardHelp centre
Portuguêsauthguard.pt

Developers · SDKs

Java SDK

  • 1 min read
  • SaaS · Self-hosted

The pt.authguard:authguard-sdk artifact uses Nimbus JOSE+JWT. It is not published yet: build it from the repository's sdks/java folder and install it into your internal Maven repository.

Dependency

<dependency>
  <groupId>pt.authguard</groupId>
  <artifactId>authguard-sdk</artifactId>
  <version>0.1.0</version>
</dependency>

Create a request and wait

IntentsClient client = IntentsClient.builder()
        .baseUrl("https://identity.example.com")
        .clientId("1c9a2b3d-4e5f-4a6b-9c7d-8e9f0a1b2c3d")
        .clientSecret(System.getenv("AUTHGUARD_CLIENT_SECRET"))
        .build();

CreateIntentRequest request = CreateIntentRequest.builder("invoice.pay")
        .subjectEmail("ana@example.com")
        .externalReference("INV-42")
        .expiresInSeconds(900)
        .field("amount", new MoneyValue("1250.00", "EUR"))
        .build();

CreateIntentResult created = client.createIntent(request, "erp-INV-42-attempt-1");
Intent intent = created.intent();
System.out.println(intent.comparisonCode());   // show it next to the operation

Intent decided = client.waitForDecision(intent.intentId());
if (decided.state() == IntentState.APPROVED) {
    // run the operation
}

waitForDecision waits up to 15 minutes, polling every 2 seconds doubling to 30. Prefer webhooks in production; cancelIntent gives 409 when the request is already over.

Webhooks

The SDK verifies the signature from the headers and the body bytes (for example in a Spring controller that receives byte[]). Deduplicate on webhook-id.

Errors

Errors are unchecked and extend AuthGuardException; an API failure is an ApiException with the status, code, message and field, and a long Retry-After is returned with getRetryAfterSeconds(). Branch on the code, not on the message text; see Errors and limits.

Error codes in this article

Article referencedev-sdk-javaquote it to support to identify this article. Checked against the product at commit 5f6607a8.