How to Configure How Do I Set Up Custom MFA Flows Using Serverless Code Hooks

Published
Length
3 min read

Luis Felipe Dias

All posts

You can build custom login steps by linking your identity provider to serverless functions. If you ask how do i set up custom mfa flows using serverless code hooks, you bind login events to small code triggers. These triggers run when a user logs in to an app or tool. They check the user context and send an extra challenge before granting entry. This setup lets your team control who gets in and when. How do i set up custom mfa flows using serverless code hooks safely A serverless code hook i

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You can build custom login steps by linking your identity provider to serverless functions. If you ask how do i set up custom mfa flows using serverless code hooks, you bind login events to small code triggers.

These triggers run when a user logs in to an app or tool. They check the user context and send an extra challenge before granting entry. This setup lets your team control who gets in and when.

How do i set up custom mfa flows using serverless code hooks safely

A serverless code hook is a small function that runs on demand. Your identity provider calls this function right after the user types a password. The identity provider pauses the login flow and waits for an answer.

First, you write a function that reads the login event data. This data includes the user identity, group roles, IP address, and device state. The function checks these details against your team security rules.

Next, the function decides if the user needs an extra check. For normal logins, the function can ask for a standard push prompt. For high-risk logins, it can ask for a hardware key or a second code.

You then link this function to the post-login trigger in your identity tool. This affects every human user and service account in that login group. You can scope the rule to admin roles or prod users first.

Always set your default rule to deny entry if the function fails. If a network error stops the hook, the login must fail closed. Keep the function timeout short so users do not wait long.

Store any third-party API keys inside a dedicated secret store. Never put secret keys in plain text inside your function settings. Limit the function role so it can only call the MFA service.

Customer Support Access to Production + Step-Up Authentication: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to check and log your custom login hooks

Before you turn on the hook for everyone, test it with one test user. Trigger a login from a known IP and check the prompt. Then trigger a login that breaks a rule to confirm it blocks entry.

Your function must write a clear log entry for every single run. Log the user ID, the time, the risk score, and the final result. Do not write secret tokens, passwords, or phone numbers into these logs.

Send these logs to a central log tool so your security team can read them. Set up alerts for high error rates or repeated failed MFA checks. A spike in failures often points to a broken script or an attack.

What login hooks leave open during active sessions

Custom MFA hooks only run at the exact moment a user logs in. Once the identity provider issues a session token, the hook stops running. It has no view into what the user does next.

When an engineer opens a database or cloud console, the login check is over. The MFA hook cannot see which queries run or which tables get changed. A valid user with a passed MFA check can still drop a prod table.

Static login checks also cannot filter sensitive rows from query results. If a user runs a broad read query, they get every matching field. You need controls inside the session to check commands and mask sensitive fields like emails or card numbers in results.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

What happens if the serverless function times out during login?

If your setup follows safe rules, the identity provider denies the login right away. You should always set your trigger to fail closed on any timeout or error.

Can I use custom MFA hooks for database and CLI logins?

Yes, if your CLI or database tool uses your identity provider for single sign-on. The user completes the browser MFA flow before the CLI gets a valid session token.

Do serverless MFA hooks slow down the user login time?

They add a small delay when the function starts up from a cold state. You can keep functions warm and limit external API calls to keep logins fast.

The query runs. The emails stay hidden.