Permissions
How the plugin authorizes personal, organization, application, and custom scopes on every route.
Every plugin route requires a session, then checks whether the user may act in the requested scope:
scopeomitted: the signed-in user, in their personal scope.{ type: 'user', id }: only ifidis the signed-in user.{ type: 'organization', id }: current members with thewebhookEndpointpermission for the action.null(application): only if yourauthorizeScopepolicy allows it. Denied by default.- Any other
type: only if yourauthorizeScopepolicy allows it. Denied by default.
Each route maps to one action:
Route under /good-webhooks/ | Action |
|---|---|
create | create |
list, get | read |
update, pause, resume, rotate-secret, send-test-event | update |
remove | delete |
Organization endpoints
Install Better Auth's organization plugin alongside goodWebhooks and add the webhookEndpoint resource to its access control:
import { createAccessControl } from 'better-auth/plugins/access'
import { organization } from 'better-auth/plugins/organization'
import {
adminAc,
defaultStatements,
memberAc,
ownerAc,
} from 'better-auth/plugins/organization/access'
const ac = createAccessControl({
...defaultStatements,
webhookEndpoint: ['create', 'read', 'update', 'delete'] as const,
})
export const auth = betterAuth({
// ...
plugins: [
organization({
ac,
roles: {
owner: ac.newRole(ownerAc.statements),
admin: ac.newRole({
...adminAc.statements,
webhookEndpoint: ['create', 'read', 'update', 'delete'],
}),
member: ac.newRole(memberAc.statements),
},
}),
goodWebhooks({ eventTypes }),
],
})The organization's creator role (owner by default) gets full access automatically. Every other role, including admin, needs an explicit grant.
Then pass the scope explicitly:
await authClient.goodWebhooks.create({
scope: { type: 'organization', id: organizationId },
url: 'https://receiver.example/webhooks',
eventTypes: ['invoice.created'],
})Each request re-checks membership and permission, so removing a member removes their access without pausing the organization's endpoints.
Application and custom scopes
Supply authorizeScope to allow application scope (null) or your own scope types. It receives the exact scope, the action, the user, and the session:
goodWebhooks({
eventTypes,
async authorizeScope({ scope, action, user, session }) {
if (scope === null) return isPlatformAdmin(user)
if (scope.type === 'project') return canManageProject(user, scope.id, action)
return false
},
})Return false for anything you do not recognize. The policy cannot loosen personal-scope or organization checks. API keys do not authenticate these routes.
Trusted server access
createBetterAuthManagement(auth) returns the provider the plugin uses internally. Its methods skip route authorization, which is what a worker needs:
import { createBetterAuthManagement } from 'good-webhooks/better-auth'
const management = await createBetterAuthManagement(auth)
await management.list({ type: 'user', id: userId }) // no session requiredKeep it in server code. If you expose any of it through your own API, authorize each request first.
Owner deletion
Deleting a user or an organization retires its endpoints, and the sender checks that an owner still exists before delivering.