Nod management API for Go
A client for each realm's management API (<issuer>/api/v1), standard library only. Go 1.23 or later.
import harpora "git.lunaor.com/lunaor/nod/sdks/go"
m := nod.New("https://auth.example.com/acme", "ops", secret)
alice, err := m.CreateUser(ctx, nod.UserCreate{Username: "alice", Email: "alice@example.com"})
err = m.AddMember(ctx, "initech", alice.ID)
err = m.EachUser(ctx, func(u nod.User) error { fmt.Println(u.Username); return nil })
err = m.EachEvent(ctx, nod.EventQuery{Type: "signin.failure"}, func(e nod.Event) error {
fmt.Println(e.Time, e.Username, e.IP)
return nil
})
var apiErr *nod.Error
if errors.As(err, &apiErr) {
fmt.Println(apiErr.Status, apiErr.Code, apiErr.Description)
}
- Credentials: a machine client of the realm granted management scopes. The client gets and renews its own token.
- Covers the realm's settings (
Realm,UpdateRealm), clients (UpdateClient,RotateClientSecret,DeleteClient), users, organizations (members, roles, invitations), roles, the realm's connections (outside providers: OpenID Connect, GitHub, OAuth 2.0, LDAP, SAML), fine-grained authorization (BatchCheckincluded), the sign-in pages' custom text (SetText), hooks for every trigger (SetHook), the waitlist (EachWaitlistEntry,AdmitWaitlist) and the security log. - Nods and ceilings:
WithApproval(ctx, approval)sends a person's approval asNod-Approvalon the calls made with that context. A call that needs a nod is an*ErrorwithChallenge(theWWW-Authenticatevalue;NodChallenge()reads the issuer andauthorization_details); one past a standing ceiling hasRetryAfter.m.Do(ctx, method, path, query, in, out)reaches anything else in the API (docs/api/management.openapi.json). - Tests run against a real server on a throwaway PostgreSQL:
go test ./...(setHARPORA_BINorNOD_BINto use an already builtharpora);go test -run Offline ./...needs no server. Not published under a module path of its own yet: that's a person's decision.
Billing
Plans (Plans, Plan, SetPlan, DeletePlan, AddPlanPrice), an organization's state (OrganizationBilling, SetOrganizationBilling; a PUT older than the stored AsOfMs answers with Stale set), the customer list (BillingOrganizations for a page, EachBillingOrganization for every page), BillingCheckout, BillingPortal and BillingSync (health).
_, err = m.AddPlanPrice(ctx, "pro", nod.PlanPrice{UnitAmount: 900, Currency: "eur", Interval: "month"})
c, err := m.BillingCheckout(ctx, "initech", nod.BillingCheckoutRequest{Plan: "pro", SuccessURL: ok, CancelURL: no})
In your app, nod.OrgPlan(claims), nod.OrgFeatures(claims) and nod.HasFeature(claims, "sso") read org_plan and org_features from a token's decoded claims (map[string]any); no org_plan is the free tier ("", no features). They verify nothing: verify the access or ID token first.