I find OAuth2-proxy the best way to restrict access to web apps using email IDs. This is typically needed in organizations using Google or Microsoft accounts.
It works with Nginx, Traefik, and Caddy. Caddy is the easiest to setup.
caddy file-server --listen :3000 will serve a test backend at http://localhost:3000.app.example.com, http://localhost:9988.localhost:4180. But if you host OAuth2-proxy on a different server/port, use that.localhost:3000.caddy run --config Caddyfilehttp_address: Use localhost:4180. But if you host OAuth2-proxy on a different server/port, use that.redirect_url: Use $SITE_ADDR/oauth2/callback. This is the OAuth Redirect URL.upstreams: Use $SITE_ADDR.email_domains: Restrict access to specific email domains. E.g. gramener.com.client_id and client_secret: From the app registration.cookie_secret: A random string. See Generating a Cookie Secret.oauth2-proxy --config oauth2-proxy.cfg$SITE_ADDR. You should be redirected to Google/Microsoft to login.$SITE_ADDR.$BACKEND_ADDR shows if you log in as a valid user./oauth2/sign_out to log out the user.oauth2/userinfo gets the user info as JSON. Useful for the backend app to get user details.