-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rules: add simple domain allow list (#192)
- Loading branch information
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
internal/cli/data/rule-template-simple-domain-allow-list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @title Email domain allow list | ||
* @overview Only allow access to users with specific allow list email domains. | ||
* @gallery true | ||
* @category access control | ||
* | ||
* This rule will only allow access to users with specific email domains. | ||
* | ||
*/ | ||
|
||
function emailDomainAllowList(user, context, callback) { | ||
// Access should only be granted to verified users. | ||
if (!user.email || !user.email_verified) { | ||
return callback(new UnauthorizedError('Access denied.')); | ||
} | ||
|
||
const allowList = ['example.com', 'example.org']; //authorized domains | ||
const userHasAccess = allowList.some(function (domain) { | ||
const emailSplit = user.email.split('@'); | ||
return emailSplit[emailSplit.length - 1].toLowerCase() === domain; | ||
}); | ||
|
||
if (!userHasAccess) { | ||
return callback(new UnauthorizedError('Access denied.')); | ||
} | ||
|
||
return callback(null, user, context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters