Admit users to applications through auth0 based on mail address
2.6K
This repository is not provided or in any way affiliated with Auth0.
Admit users to applications through auth0 based on mail address
The auth0-user-gatekeeper is a simple way to admit users to applications based on their email address.
It allows maintaining the allow list for mails and domains outside the auth0 tenant.
Set up is a straightforward as 1-2-3.
services:
gatekeeper:
image: timoreymann/auth0-user-gatekeeper:latest
platform: linux/amd64
restart: always
ports:
- 2025:2025
volumes:
- ./config.yaml:/etc/auth0-user-gatekeeper/config.yml
config.yaml
token: <token that needs to be provided by the auth0 action>
# List of allowed domains (can be omitted)
allowed_domains:
- your.tld
# List of allowed mails (can be omitted)
allowed_mails:
- [email protected]
You will have to create two actions for each tenant you want to use the gatekeeper.
Actions > LibraryCreate ActionCreate custom actionpermit-only-allowed-mails-to-registerPre User RegistrationCreateAdd dependencyauth0-user-gatekeeperconst {UserGateKeeper} = require("auth0-user-gatekeeper");
/**
* @param {Event} event - Details about the context and user that is attempting to register.
* @param {PreUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the signup.
*/
exports.onExecutePreUserRegistration = async (event, api) => {
/** @type {UserGateKeeper} */
const gatekeeper = new UserGateKeeper({
baseUrl: "https://your-reverse-proxy.tld",
timeoutMs: 1 * 1_000,
token: "<token from server config.yml>"
});
const {isAllowed, reason} = await gatekeeper.isAllowedEmail(event.user.email);
if(!isAllowed) {
api.access.deny(reason, "You are not allowed to register.")
}
};
Actions > LibraryCreate ActionCreate custom actionpermit-only-allowed-mails-to-loginLogin / Post LoginCreateAdd dependencyauth0-user-gatekeeperconst { UserGateKeeper } = require("auth0-user-gatekeeper");
/**
* @param {Event} event - Details about the context and user that is attempting to register.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the signup.
*/
exports.onExecutePostLogin = async (event, api) => {
if(!event.user.email_verified) {
api.access.deny("E-Mail not verified")
return
}
/** @type {UserGateKeeper} */
const gatekeeper = new UserGateKeeper({
baseUrl: "https://your-reverse-proxy.tld",
timeoutMs: 1 * 1_000,
token: "<token from server config.yml>"
});
const { isAllowed } = await gatekeeper.isAllowedEmail(event.user.email);
if (!isAllowed) {
api.access.deny("You are not allowed to login.")
}
};
Actions > TriggersSignup & Login, click on pre-user-registrationpermit-only-allowed-mails-to-registerStartApplyActions > Triggerspost-loginpermit-only-allowed-mails-to-loginStartApplyContent type
Image
Digest
sha256:8f0a8ad81…
Size
8.4 MB
Last updated
about 1 month ago
docker pull timoreymann/auth0-user-gatekeeper