-
-
Notifications
You must be signed in to change notification settings - Fork 152
add email mfa factor #499
add email mfa factor #499
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -92,6 +92,11 @@ func newGuardian() *schema.Resource { | |||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
"email": { | ||||||||||||||||||||||||||||||
Type: schema.TypeBool, | ||||||||||||||||||||||||||||||
Optional: true, | ||||||||||||||||||||||||||||||
Default: false, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
@@ -103,6 +108,9 @@ func createGuardian(d *schema.ResourceData, m interface{}) error { | |||||||||||||||||||||||||||||
func deleteGuardian(d *schema.ResourceData, m interface{}) error { | ||||||||||||||||||||||||||||||
api := m.(*management.Management) | ||||||||||||||||||||||||||||||
api.Guardian.MultiFactor.Phone.Enable(false) | ||||||||||||||||||||||||||||||
if err := api.Guardian.MultiFactor.Email.Enable(false); err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
d.SetId("") | ||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
@@ -118,7 +126,16 @@ func updateGuardian(d *schema.ResourceData, m interface{}) (err error) { | |||||||||||||||||||||||||||||
err = api.Guardian.MultiFactor.UpdatePolicy(&management.MultiFactorPolicies{p}) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
//TODO: Extend for other MFA types | ||||||||||||||||||||||||||||||
if err := updatePhoneFactor(d, api); err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
if err := updateEmailFactor(d, api); err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
return readGuardian(d, m) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
func updatePhoneFactor(d *schema.ResourceData, api *management.Management) error { | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably simplify the logic inside this func as follows:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely easier on the eyes with reducing the nesting, thanks for raising it about this & the other func! Had to change this one slightly, as phone needs to be enabled before it's configured. Also added api.Guardian.MultiFactor.Phone.Enable(false) for the negative case, as this means it's not present/being removed from state and we need to toggle it off. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, thanks @phil-f ! Awesome work here |
||||||||||||||||||||||||||||||
ok, err := factorShouldBeUpdated(d, "phone") | ||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
|
@@ -131,11 +148,20 @@ func updateGuardian(d *schema.ResourceData, m interface{}) (err error) { | |||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||
api.Guardian.MultiFactor.Phone.Enable(false) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
return readGuardian(d, m) | ||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
func configurePhone(d *schema.ResourceData, api *management.Management) (err error) { | ||||||||||||||||||||||||||||||
func updateEmailFactor(d *schema.ResourceData, api *management.Management) error { | ||||||||||||||||||||||||||||||
if changed := d.HasChange("email"); changed { | ||||||||||||||||||||||||||||||
enabled := d.Get("email").(bool) | ||||||||||||||||||||||||||||||
if err := api.Guardian.MultiFactor.Email.Enable(enabled); err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can return here directly and remove 1 extra indentation level.
Suggested change
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
func configurePhone(d *schema.ResourceData, api *management.Management) (err error) { | ||||||||||||||||||||||||||||||
md := make(MapData) | ||||||||||||||||||||||||||||||
List(d, "phone").Elem(func(d ResourceData) { | ||||||||||||||||||||||||||||||
md.Set("provider", String(d, "provider", HasChange())) | ||||||||||||||||||||||||||||||
|
@@ -241,6 +267,7 @@ func readGuardian(d *schema.ResourceData, m interface{}) error { | |||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
ok, err := factorShouldBeUpdated(d, "phone") | ||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
|
@@ -254,6 +281,17 @@ func readGuardian(d *schema.ResourceData, m interface{}) error { | |||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
factors, err := api.Guardian.MultiFactor.List() | ||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
for _, v := range factors { | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it more readable to avoid the switch here? I think it could be just if v.Name != nil && *v.Name == "email"{
d.Set("email", v.Enabled)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you mean, I think we can leave the switch there 馃憤 But isn't there still a possible null pointer error here that is not adressed by your code? If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd agree that @apamildner 's if statement is slightly clearer. If and when one-time-password and recovery-code get added, a switch will likely make more sense. |
||||||||||||||||||||||||||||||
switch *v.Name { | ||||||||||||||||||||||||||||||
case "email": | ||||||||||||||||||||||||||||||
d.Set("email", v.Enabled) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,11 @@ resource "auth0_guardian" "default" { | |
provider = "auth0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not part of your code but might just clean it up: I'm unable to comment on the specific line, but this file has a typo at line 5 which could be adressed: With this reasource, you can configure some of the MFA options -> With this resource, you can configure some of the MFA options |
||
message_types = ["sms"] | ||
options { | ||
enrollment_message = "{{code}}} is your verification code for {{tenant.friendly_name}}. Please enter this code to verify your enrollment" | ||
enrollment_message = "{{code}} is your verification code for {{tenant.friendly_name}}. Please enter this code to verify your enrollment" | ||
verification_message = "{{code}} is your verification code for {{tenant.friendly_name}}" | ||
} | ||
} | ||
email = true | ||
} | ||
``` | ||
|
||
|
@@ -32,6 +33,7 @@ Arguments accepted by this resource include: | |
|
||
* `policy` - (Required) String. Policy to use. Available options are `never`, `all-applications` and `confidence-score`. The option `confidence-score` means the trigger of MFA will be adaptive. See [Auth0 docs](https://auth0.com/docs/mfa/adaptive-mfa) | ||
* `phone` - (Optional) List(Resource). Configuration settings for the phone MFA. For details, see [Phone](#phone). | ||
* `email` - (Optional) Boolean. Indicates whether or not email MFA is enabled. | ||
|
||
### Phone | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you mentioned - I probably forgot to handle the error here so you can definitely add it in this PR 馃憤
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it seems like
isFactorEnabled
function is unused (also my bad), might just remove it in this PR 馃憤