Register an HTTPS endpoint under Sign-in hooks in the Auth admin. Auth calls it at one point of every sign-in and waits at most its timeout (500 to 10,000 ms).
| Trigger | When | May |
|---|---|---|
| pre_registration | Someone signs up on a hosted page, before the verification email | refuse |
| post_login | After the person proved who they are, before the application gets a code | refuse |
| pre_token_issue | Before every token: code, refresh, device and machine tokens | add claims, or refuse |
The call and the answer
Auth posts a JSON event signed like a webhook: check it with verifyWebhook and the hook's own secret, shown once when you add the hook. Answer with a decision.
import { verifyWebhook } from '@smartdesk/auth-sdk'
app.post('/hooks/sign-in', express.text({ type: 'application/json' }), async (req, res) => {
const ok = await verifyWebhook({ secret: process.env.HOOK_SECRET, body: req.body,
timestamp: req.get('Ziqme-Webhook-Timestamp'), signature: req.get('Ziqme-Webhook-Signature') })
if (!ok) return res.sendStatus(401)
const event = JSON.parse(req.body)
if (event.type === 'post_login' && await trialEnded(event.user.id)) {
return res.json({ decision: 'deny', reason: 'Your trial has ended.' })
}
if (event.type === 'pre_token_issue') return res.json({ decision: 'allow', claims: { plan: await planOf(event.user.id) } })
res.json({ decision: 'allow' })
})- A refusal stops the sign-in; its reason is shown to the person or sent to the application as access_denied.
- Claims are added to the access and ID tokens, at most 20, never over a claim Auth sets itself.
- A hook that times out or errors is skipped, or, when it fails closed, the sign-in is refused with a generic message.
- Every refusal and failure is in the audit log.