-
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.
Pick 5 templates to start.
- Loading branch information
Showing
7 changed files
with
153 additions
and
23 deletions.
There are no files selected for viewing
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,8 @@ | ||
function addEmailToAccessToken(user, context, callback) { | ||
// This rule adds the authenticated user's email address to the access token. | ||
|
||
var namespace = 'https://example.com/'; | ||
|
||
context.accessToken[namespace + 'email'] = user.email; | ||
return callback(null, user, context); | ||
} |
12 changes: 12 additions & 0 deletions
12
internal/cli/data/rule-template-check-last-password-reset.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,12 @@ | ||
function checkLastPasswordReset(user, context, callback) { | ||
function daydiff(first, second) { | ||
return (second - first) / (1000 * 60 * 60 * 24); | ||
} | ||
|
||
const last_password_change = user.last_password_reset || user.created_at; | ||
|
||
if (daydiff(new Date(last_password_change), new Date()) > 30) { | ||
return callback(new UnauthorizedError('please change your password')); | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function ipAddressAllowList(user, context, callback) { | ||
const allowlist = ['1.2.3.4', '2.3.4.5']; // authorized IPs | ||
const userHasAccess = allowlist.some(function (ip) { | ||
return context.request.ip === ip; | ||
}); | ||
|
||
if (!userHasAccess) { | ||
return callback(new Error('Access denied from this IP address.')); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function ipAddressDenylist(user, context, callback) { | ||
const denylist = ['1.2.3.4', '2.3.4.5']; // unauthorized IPs | ||
const notAuthorized = denylist.some(function (ip) { | ||
return context.request.ip === ip; | ||
}); | ||
|
||
if (notAuthorized) { | ||
return callback( | ||
new UnauthorizedError('Access denied from this IP address.') | ||
); | ||
} | ||
|
||
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
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