Menu AuthGuardHelp centre
Portuguêsauthguard.pt

Developers · SDKs

Go SDK

  • 1 min read
  • SaaS · Self-hosted

The Go SDK lives in the repository's sdks/go folder (package authguard) and uses go-oidc/v3 with go-jose/v4. It is not published yet: point your go.mod at the local copy with a replace directive.

Install

go mod edit -require=<sdks/go module>@v0.1.0 -replace=<sdks/go module>=../authguard/sdks/go

The exact module name is in the go.mod of the sdks/go folder.

Create a request and wait

intents, err := authguard.NewIntentsClient(authguard.IntentsConfig{
	BaseURL:      "https://identity.example.com",
	ClientID:     os.Getenv("AUTHGUARD_CLIENT_ID"),
	ClientSecret: os.Getenv("AUTHGUARD_CLIENT_SECRET"),
})
if err != nil {
	return err
}

result, err := intents.CreateIntent(ctx, authguard.CreateIntentRequest{
	OperationType:     "invoice.pay",
	SubjectEmail:      "ana@example.com",
	ExternalReference: "INV-42",
	ExpiresInSeconds:  900,
	Fields: map[string]any{
		"amount": authguard.MoneyValue{Amount: "1250.00", Currency: "EUR"},
	},
}, "erp-INV-42-attempt-1")
if err != nil {
	return err
}
fmt.Println(result.Intent.ComparisonCode) // show it next to the operation

decided, err := intents.WaitForDecision(ctx, result.Intent.IntentID,
	&authguard.WaitOptions{Timeout: 15 * time.Minute})

Webhooks, receipts and OIDC

The package has functions to verify Standard Webhooks, the request digest and the receipt, and the OIDC flow with PKCE. Always use the raw body bytes and deduplicate on webhook-id.

Error codes in this article

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