Skip to content

Commit f94c606

Browse files
authored
Add missing prompt custom text and implement prompt screen partial in terraform generator (#1426)
* feat(prompt): update custom text prompt types to add missing items - Reformatted the `customTextPromptTypes` array for better readability. - Added new prompt types: `email_identifier_challenge` and `passkeys`. - This change enhances the prompt handling capabilities in the `terraform_fetcher.go` file. * feat(prompt): add support for screen partial prompts - Introduced `promptScreenPartialResourceFetcher` to handle fetching data for screen partial prompts. - Updated `parseResourceFetchers` method in `terraform.go` to include the new fetcher for "auth0_prompt_screen_partial". - Added a mapping for screen partial prompt types to their corresponding screens in `terraform_fetcher.go`. - This enhancement allows for better management and retrieval of screen partial prompts in the CLI. * feat(prompt): update custom text prompt types and clean up code - Added missing custom text prompt types including "login-passwordless", "phone-identifier-enrollment", and others to enhance prompt coverage. - Removed outdated TODO comments to improve code clarity. - Updated references in comments for better documentation and accuracy. * feat(prompt): enhance custom text prompts and add screen partial support - Refactored the promptTypes array in TestPromptCustomTextResourceFetcher to improve readability and added new prompt types. - Introduced Test_promptScreenPartialResourceFetcher to validate the retrieval of screen partial prompts data. - Ensured that the new tests cover various scenarios for screen partial prompts, enhancing overall test coverage. * feat(prompt): add support for screen partial prompts in Terraform config - Updated the default resources list to include `auth0_prompt_screen_partial`. - This change allows users to generate Terraform configurations for screen partial prompts, enhancing the flexibility of the `auth0 terraform generate` command. * feat(prompt): remove unused custom text prompt types - Eliminated "async-approval-flow" from the customTextPromptTypes slice in terraform_fetcher.go. - This prompt type is not supported in go-auth0 and terraform provider. * feat(prompt): streamline custom text prompt types in code - Consolidated the definition of `customTextPromptTypes` in `terraform_fetcher.go` and `terraform_fetcher_test.go` to a single line for improved readability. - This change reduces visual clutter and maintains consistency across the codebase. - No functional changes were made; the prompt types remain the same. * fix(prompt): update assertion in Test_promptScreenPartialResourceFetcher_FetchData - Changed assertion from assert.Equal to assert.ElementsMatch to ensure that the order of elements in the fetched data does not affect the test outcome. * feat(auth): add new required scopes for organization and user profiles - Added "read:organization_discovery_domains", "read:self_service_profiles", and "read:user_attribute_profiles" to the RequiredScopes variable. - This change enhances the authentication flow by allowing access to additional user and organization-related resources. * fix(tests): uncomment and restore Terraform test cases - Restored the previously commented-out test cases for Terraform integration. - Comment out failing quickstart integration test * fix(tests): rename quickstart test cases to disabled file - Renamed quickstart test cases from `quickstarts-test-cases.yaml` to `quickstarts-test-cases.yaml.disabled`. - This change skips running quickstarts-test-cases. - Commenting out tests led to `could not find test with pattern: ` error, hence renamed the file. * fix(tests): add dummy test case to quickstarts * fix(terraform): improve error message for terraform plan failure - Enhanced the warning message in the generateTerraformCmdRun function to include the error details when terraform plan fails. - This change provides clearer feedback to users, aiding in troubleshooting by specifying the nature of the error encountered. * fix(tests): Skip only download quickstart test * chore(terraform): address review comments - Renamed `customTextPromptTypes` to `customTextPrompts` for clarity. - Updated `customTextPromptOptions` to use the new prompt variable. - Enhanced error message in `generateTerraformCmdRun`. - Adjusted test cases in `terraform_fetcher_test.go` to reflect prompt name changes. * fix(tests): re-enable download quickstart test case - Restored the previously commented-out download quickstart test case. * fix(cli): add pre-login organization picker to prompt screen map - Updated the PromptScreenMap in universal_login_customize.go to include "pre-login-organization-picker" under the "organizations" key. * fix(go.mod): update go-auth0 dependency to v1.33.0 - Updated the version of the `github.com/auth0/go-auth0` dependency from v1.32.1 to v1.33.0 in `go.mod`. - The corresponding entries in `go.sum` have been added to reflect the updated version.
1 parent bc97da6 commit f94c606

11 files changed

Lines changed: 94 additions & 25 deletions

docs/auth0_terraform_generate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ auth0 terraform generate [flags]
3333
```
3434
--force Skip confirmation.
3535
-o, --output-dir string Output directory for the generated Terraform config files. If not provided, the files will be saved in the current working directory. (default "./")
36-
-r, --resources strings Resource types to generate Terraform config for. If not provided, config files for all available resources will be generated. (default [auth0_action,auth0_attack_protection,auth0_branding,auth0_branding_theme,auth0_phone_provider,auth0_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_flow,auth0_flow_vault_connection,auth0_form,auth0_email_provider,auth0_email_template,auth0_guardian,auth0_log_stream,auth0_network_acl,auth0_organization,auth0_pages,auth0_prompt,auth0_prompt_custom_text,auth0_prompt_screen_renderer,auth0_resource_server,auth0_role,auth0_self_service_profile,auth0_tenant,auth0_trigger_actions,auth0_user_attribute_profile])
36+
-r, --resources strings Resource types to generate Terraform config for. If not provided, config files for all available resources will be generated. (default [auth0_action,auth0_attack_protection,auth0_branding,auth0_branding_theme,auth0_phone_provider,auth0_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_flow,auth0_flow_vault_connection,auth0_form,auth0_email_provider,auth0_email_template,auth0_guardian,auth0_log_stream,auth0_network_acl,auth0_organization,auth0_pages,auth0_prompt,auth0_prompt_custom_text,auth0_prompt_screen_renderer,auth0_resource_server,auth0_role,auth0_self_service_profile,auth0_tenant,auth0_trigger_actions,auth0_user_attribute_profile,auth0_prompt_screen_partial])
3737
-v, --tf-version string Terraform version that ought to be used while generating the terraform files for resources. If not provided, 1.5.0 is used by default (default "1.5.0")
3838
```
3939

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/AlecAivazis/survey/v2 v2.3.7
77
github.com/PuerkitoBio/rehttp v1.4.0
88
github.com/atotto/clipboard v0.1.4
9-
github.com/auth0/go-auth0 v1.32.1
9+
github.com/auth0/go-auth0 v1.33.0
1010
github.com/briandowns/spinner v1.23.2
1111
github.com/charmbracelet/glamour v0.10.0
1212
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
2424
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
2525
github.com/auth0/go-auth0 v1.32.1 h1:AAXQqaNaFZWkRm2bg5mVVXpqDLmusv7v238uIaxuFpo=
2626
github.com/auth0/go-auth0 v1.32.1/go.mod h1:32sQB1uAn+99fJo6N819EniKq8h785p0ag0lMWhiTaE=
27+
github.com/auth0/go-auth0 v1.33.0 h1:7qx0UCA6Tn2udnEVA35xzKsseh/R9559f+nnGcUI0Ss=
28+
github.com/auth0/go-auth0 v1.33.0/go.mod h1:32sQB1uAn+99fJo6N819EniKq8h785p0ag0lMWhiTaE=
2729
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48=
2830
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0/go.mod h1:6L7zgvqo0idzI7IO8de6ZC051AfXb5ipkIJ7bIA2tGA=
2931
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=

internal/auth/auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ var RequiredScopes = []string{
149149
"read:event_streams", "create:event_streams", "update:event_streams", "delete:event_streams",
150150
"read:network_acls", "create:network_acls", "update:network_acls", "delete:network_acls",
151151
"read:token_exchange_profiles", "create:token_exchange_profiles", "update:token_exchange_profiles", "delete:token_exchange_profiles",
152+
"read:organization_discovery_domains", "read:self_service_profiles", "read:user_attribute_profiles",
152153
}
153154

154155
// GetDeviceCode kicks-off the device authentication flow by requesting

internal/cli/acul_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ var (
158158
"accept-invitation": "invitation",
159159
"organization-picker": "organizations",
160160
"organization-selection": "organizations",
161+
"pre-login-organization-picker": "organizations",
161162
"device-code-activation": "device-flow",
162163
"device-code-activation-allowed": "device-flow",
163164
"device-code-activation-denied": "device-flow",

internal/cli/prompts_custom_text.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func universalLoginPromptsTextCmd(cli *cli) *cobra.Command {
6666

6767
func customTextPromptOptions(_ context.Context) (pickerOptions, error) {
6868
var opts pickerOptions
69-
for _, promptType := range customTextPromptTypes {
70-
opts = append(opts, pickerOption{value: promptType, label: promptType})
69+
for _, prompt := range customTextPrompts {
70+
opts = append(opts, pickerOption{value: prompt, label: prompt})
7171
}
7272
return opts, nil
7373
}

internal/cli/terraform.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ func (i *terraformInputs) parseResourceFetchers(api *auth0.API) ([]resourceDataF
109109
fetchers = append(fetchers, &promptResourceFetcher{})
110110
case "auth0_prompt_custom_text":
111111
fetchers = append(fetchers, &promptCustomTextResourceFetcherResourceFetcher{api})
112+
case "auth0_prompt_screen_partial":
113+
fetchers = append(fetchers, &promptScreenPartialResourceFetcher{})
112114
case "auth0_prompt_screen_renderer":
113115
fetchers = append(fetchers, &promptScreenRendererResourceFetcher{api})
114116
case "auth0_resource_server", "auth0_resource_server_scopes":

internal/cli/terraform_fetcher.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var (
15-
defaultResources = []string{"auth0_action", "auth0_attack_protection", "auth0_branding", "auth0_branding_theme", "auth0_phone_provider", "auth0_client", "auth0_client_grant", "auth0_connection", "auth0_custom_domain", "auth0_flow", "auth0_flow_vault_connection", "auth0_form", "auth0_email_provider", "auth0_email_template", "auth0_guardian", "auth0_log_stream", "auth0_network_acl", "auth0_organization", "auth0_pages", "auth0_prompt", "auth0_prompt_custom_text", "auth0_prompt_screen_renderer", "auth0_resource_server", "auth0_role", "auth0_self_service_profile", "auth0_tenant", "auth0_trigger_actions", "auth0_user_attribute_profile"}
15+
defaultResources = []string{"auth0_action", "auth0_attack_protection", "auth0_branding", "auth0_branding_theme", "auth0_phone_provider", "auth0_client", "auth0_client_grant", "auth0_connection", "auth0_custom_domain", "auth0_flow", "auth0_flow_vault_connection", "auth0_form", "auth0_email_provider", "auth0_email_template", "auth0_guardian", "auth0_log_stream", "auth0_network_acl", "auth0_organization", "auth0_pages", "auth0_prompt", "auth0_prompt_custom_text", "auth0_prompt_screen_renderer", "auth0_resource_server", "auth0_role", "auth0_self_service_profile", "auth0_tenant", "auth0_trigger_actions", "auth0_user_attribute_profile", "auth0_prompt_screen_partial"}
1616
)
1717

1818
type (
@@ -107,6 +107,8 @@ type (
107107
api *auth0.API
108108
}
109109

110+
promptScreenPartialResourceFetcher struct{}
111+
110112
roleResourceFetcher struct {
111113
api *auth0.API
112114
}
@@ -528,7 +530,8 @@ func (f *promptResourceFetcher) FetchData(_ context.Context) (importDataList, er
528530
}, nil
529531
}
530532

531-
var customTextPromptTypes = []string{"login", "login-id", "login-password", "login-email-verification", "signup", "signup-id", "signup-password", "reset-password", "consent", "mfa-push", "mfa-otp", "mfa-voice", "mfa-phone", "mfa-webauthn", "mfa-sms", "mfa-email", "mfa-recovery-code", "mfa", "status", "device-flow", "email-verification", "email-otp-challenge", "organizations", "invitation", "common"}
533+
// Referred from 'prompt' path options in: https://auth0.com/docs/api/management/v2/prompts/get-custom-text-by-language
534+
var customTextPrompts = []string{"login", "login-id", "login-password", "login-email-verification", "signup", "signup-id", "signup-password", "reset-password", "consent", "mfa-push", "mfa-otp", "mfa-voice", "mfa-phone", "mfa-webauthn", "mfa-sms", "mfa-email", "mfa-recovery-code", "mfa", "status", "device-flow", "email-verification", "email-otp-challenge", "organizations", "invitation", "common", "email-identifier-challenge", "passkeys", "login-passwordless", "phone-identifier-enrollment", "phone-identifier-challenge", "custom-form", "customized-consent", "logout", "captcha", "brute-force-protection"}
532535

533536
func (f *promptCustomTextResourceFetcherResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
534537
tenant, err := f.api.Tenant.Read(ctx)
@@ -538,10 +541,37 @@ func (f *promptCustomTextResourceFetcherResourceFetcher) FetchData(ctx context.C
538541

539542
var data importDataList
540543
for _, language := range tenant.GetEnabledLocales() {
541-
for _, promptType := range customTextPromptTypes {
544+
for _, prompt := range customTextPrompts {
545+
data = append(data, importDataItem{
546+
ResourceName: "auth0_prompt_custom_text." + sanitizeResourceName(language+"_"+prompt),
547+
ImportID: prompt + "::" + language,
548+
})
549+
}
550+
}
551+
552+
return data, nil
553+
}
554+
555+
// Referred from prompt 'path' options in: https://auth0.com/docs/api/management/v2/prompts/get-partials
556+
var screenPartialPromptToScreenMap = map[string][]string{
557+
"login": {"login"},
558+
"login-id": {"login-id"},
559+
"login-password": {"login-password"},
560+
"login-passwordless": {"login-passwordless-sms-otp", "login-passwordless-email-code"},
561+
"signup": {"signup"},
562+
"signup-id": {"signup-id"},
563+
"signup-password": {"signup-password"},
564+
"customized-consent": {"customized-consent"},
565+
}
566+
567+
func (f *promptScreenPartialResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
568+
var data importDataList
569+
570+
for prompt, screens := range screenPartialPromptToScreenMap {
571+
for _, screen := range screens {
542572
data = append(data, importDataItem{
543-
ResourceName: "auth0_prompt_custom_text." + sanitizeResourceName(language+"_"+promptType),
544-
ImportID: promptType + "::" + language,
573+
ResourceName: "auth0_prompt_screen_partial." + sanitizeResourceName(prompt+"_"+screen),
574+
ImportID: prompt + ":" + screen,
545575
})
546576
}
547577
}

internal/cli/terraform_fetcher_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ func TestPromptCustomTextResourceFetcher_FetchData(t *testing.T) {
16941694
},
16951695
}
16961696

1697-
promptTypes := []string{"login", "login-id", "login-password", "login-email-verification", "signup", "signup-id", "signup-password", "reset-password", "consent", "mfa-push", "mfa-otp", "mfa-voice", "mfa-phone", "mfa-webauthn", "mfa-sms", "mfa-email", "mfa-recovery-code", "mfa", "status", "device-flow", "email-verification", "email-otp-challenge", "organizations", "invitation", "common"}
1697+
promptTypes := []string{"login", "login-id", "login-password", "login-email-verification", "signup", "signup-id", "signup-password", "reset-password", "consent", "mfa-push", "mfa-otp", "mfa-voice", "mfa-phone", "mfa-webauthn", "mfa-sms", "mfa-email", "mfa-recovery-code", "mfa", "status", "device-flow", "email-verification", "email-otp-challenge", "organizations", "invitation", "common", "email-identifier-challenge", "passkeys", "login-passwordless", "phone-identifier-enrollment", "phone-identifier-challenge", "custom-form", "customized-consent", "logout", "captcha", "brute-force-protection"}
16981698

16991699
expectedData := importDataList{}
17001700
for _, enabledLocale := range mockEnabledLocales {
@@ -2206,3 +2206,36 @@ func TestUserAttributeProfileResourceFetcher(t *testing.T) {
22062206
assert.Greater(t, len(data[0].ImportID), 0)
22072207
})
22082208
}
2209+
2210+
func Test_promptScreenPartialResourceFetcher_FetchData(t *testing.T) {
2211+
t.Run("it successfully retrieves screen partial prompts data", func(t *testing.T) {
2212+
fetcher := promptScreenPartialResourceFetcher{}
2213+
2214+
original := screenPartialPromptToScreenMap
2215+
defer func() { screenPartialPromptToScreenMap = original }()
2216+
2217+
screenPartialPromptToScreenMap = map[string][]string{
2218+
"login": {"login"},
2219+
"login-passwordless": {"login-passwordless-sms-otp", "login-passwordless-email-code"},
2220+
}
2221+
2222+
expectedData := importDataList{
2223+
{
2224+
ResourceName: "auth0_prompt_screen_partial.login_login",
2225+
ImportID: "login:login",
2226+
},
2227+
{
2228+
ResourceName: "auth0_prompt_screen_partial.login_passwordless_login_passwordless_sms_otp",
2229+
ImportID: "login-passwordless:login-passwordless-sms-otp",
2230+
},
2231+
{
2232+
ResourceName: "auth0_prompt_screen_partial.login_passwordless_login_passwordless_email_code",
2233+
ImportID: "login-passwordless:login-passwordless-email-code",
2234+
},
2235+
}
2236+
2237+
data, err := fetcher.FetchData(context.Background())
2238+
assert.NoError(t, err)
2239+
assert.ElementsMatch(t, expectedData, data)
2240+
})
2241+
}

internal/cli/universal_login_customize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ var PromptScreenMap = map[string][]string{
120120
"mfa-voice": {"mfa-voice-challenge", "mfa-voice-enrollment"},
121121
"mfa-recovery-code": {"mfa-recovery-code-challenge", "mfa-recovery-code-enrollment", "mfa-recovery-code-challenge-new-code"},
122122
"invitation": {"accept-invitation"},
123-
"organizations": {"organization-picker", "organization-selection"},
123+
"organizations": {"organization-picker", "organization-selection", "pre-login-organization-picker"},
124124
"device-flow": {"device-code-activation", "device-code-activation-allowed", "device-code-activation-denied", "device-code-confirmation"},
125125
"common": {"redeem-ticket"},
126126
"email-verification": {"email-verification-result"},

0 commit comments

Comments
 (0)