-
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.
* step 1: restore from our earlier iteration * Very rough first pass on create * Better name * Wrap up editor prompt / rules create flow * Rules: CRUD is done * Cleanup * Lint * Finalize rules Pick 5 templates to start. * Tweak flags so we don't repeat ourselves too much * Add docs for flags.Required() * Switch to using new ansi.Waiting for most cases * Ask name after fetching rule * Subtle fix: update && not required should not prompt * Cleanup * Add a note for now that we're going to do something for next time * Remove `Required()` use * Amend to have AlwaysPrompt logic
- Loading branch information
Showing
17 changed files
with
720 additions
and
18 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:generate mockgen -source=rule.go -destination=rule_mock.go -package=auth0 | ||
|
||
package auth0 | ||
|
||
import "gopkg.in/auth0.v5/management" | ||
|
||
type RuleAPI interface { | ||
// Create a new rule. | ||
// | ||
// Note: Changing a rule's stage of execution from the default `login_success` | ||
// can change the rule's function signature to have user omitted. | ||
Create(r *management.Rule, opts ...management.RequestOption) error | ||
|
||
// Retrieve rule details. Accepts a list of fields to include or exclude in the result. | ||
Read(id string, opts ...management.RequestOption) (r *management.Rule, err error) | ||
|
||
// Update an existing rule. | ||
Update(id string, r *management.Rule, opts ...management.RequestOption) error | ||
|
||
// Delete a rule. | ||
Delete(id string, opts ...management.RequestOption) error | ||
|
||
// List all rules. | ||
List(opts ...management.RequestOption) (r *management.RuleList, err error) | ||
} |
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
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,3 @@ | ||
function(user, context, cb) { | ||
cb(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
Oops, something went wrong.