-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for rendering the settings of prompt-screen (#1077)
* 1. Support resource and data_source for render settings of prompt-screen 2. Include unit tests, examples and docs 3. Update Go-Auth0's dependent version * Add unit tests for delete scenario for auth0_prompt_screen_renderer * Include E2E test Recordings and few edge case scenario for auth0_prompt_screen_renderer resource * Fix lint issue * Handle null case for head_tags & update supported screens * Update docs,unit tests and integration tests recordings * Update the screen Name for reset-password-mfa-push-challenge-push * Update the latest go-auth0 version * Update the renderingMode type to ENUM. * Update the renderingMode type to ENUM.
- Loading branch information
1 parent
800b1b8
commit ab8ca15
Showing
18 changed files
with
1,941 additions
and
9 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,30 @@ | ||
--- | ||
page_title: "Data Source: auth0_prompt_screen_renderer" | ||
description: |- | ||
Data source to retrieve a specific Auth0 prompt screen settings by prompt_type and screen_name | ||
--- | ||
|
||
# Data Source: auth0_prompt_screen_renderer | ||
|
||
Data source to retrieve a specific Auth0 prompt screen settings by `prompt_type` and `screen_name` | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `prompt_type` (String) The type of prompt to customize. | ||
- `screen_name` (String) The screen name associated with the prompt type. | ||
|
||
### Read-Only | ||
|
||
- `context_configuration` (Set of String) Context values to make available | ||
- `default_head_tags_disabled` (Boolean) Override Universal Login default head tags | ||
- `head_tags` (String) An array of head tags | ||
- `id` (String) The ID of this resource. | ||
- `rendering_mode` (String) Rendering modeOptions are: `standard`, `advanced`. | ||
- `tenant` (String) Tenant ID | ||
|
||
|
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,88 @@ | ||
--- | ||
page_title: "Resource: auth0_prompt_screen_renderer" | ||
description: |- | ||
With this resource, you can Configure the render settings for a specific screen.You can read more about this. | ||
--- | ||
|
||
# Resource: auth0_prompt_screen_renderer | ||
|
||
With this resource, you can Configure the render settings for a specific screen.You can read more about this. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "auth0_prompt_screen_renderer" "prompt_screen_renderer" { | ||
prompt_type = "login-id" | ||
screen_name = "login-id" | ||
rendering_mode = "advanced" | ||
default_head_tags_disabled = false | ||
context_configuration = [ | ||
"branding.settings", | ||
"branding.themes.default", | ||
"client.logo_uri", | ||
"client.description", | ||
"client.metadata.key", | ||
"organization.display_name", | ||
"organization.branding", | ||
"organization.metadata.key", | ||
"screen.texts", | ||
"tenant.name", | ||
"tenant.friendly_name", | ||
"tenant.enabled_locales", | ||
"untrusted_data.submitted_form_data", | ||
"untrusted_data.authorization_params.login_hint", | ||
"untrusted_data.authorization_params.screen_hint", | ||
"untrusted_data.authorization_params.ui_locales", | ||
"untrusted_data.authorization_params.ext-.key", | ||
"transaction.connection.metadata.key" | ||
] | ||
head_tags = jsonencode([ | ||
{ | ||
attributes : { | ||
"async" : true, | ||
"defer" : true, | ||
"integrity" : [ | ||
"sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" | ||
], | ||
"src" : "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" | ||
}, | ||
tag : "script" | ||
} | ||
]) | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `prompt_type` (String) The prompt that you are configuring settings for. Options are: `signup-id`, `signup`, `signup-password`, `login`, `login-id`, `login-password`, `login-passwordless`, `login-email-verification`, `phone-identifier-enrollment`, `phone-identifier-challenge`, `email-identifier-challenge`, `reset-password`, `custom-form`, `consent`, `customized-consent`, `logout`, `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`, `passkeys`, `captcha`. | ||
- `screen_name` (String) The screen that you are configuring settings for. Options are: `login`, `login-id`, `login-password`, `signup`, `signup-id`, `signup-password`, `login-passwordless-sms-otp`, `login-passwordless-email-code`, `login-passwordless-email-link`, `login-email-verification`, `phone-identifier-enrollment`, `phone-identifier-challenge`, `email-identifier-challenge`, `reset-password-request`, `reset-password-email`, `reset-password`, `reset-password-success`, `reset-password-error`, `reset-password-mfa-email-challenge`, `reset-password-mfa-otp-challenge`, `reset-password-mfa-phone-challenge`, `reset-password-mfa-push-challenge-push`, `reset-password-mfa-recovery-code-challenge`, `reset-password-mfa-sms-challenge`, `reset-password-mfa-voice-challenge`, `reset-password-mfa-webauthn-platform-challenge`, `reset-password-mfa-webauthn-roaming-challenge`, `custom-form`, `consent`, `customized-consent`, `logout`, `logout-complete`, `logout-aborted`, `mfa-push-welcome`, `mfa-push-enrollment-qr`, `mfa-push-enrollment-code`, `mfa-push-success`, `mfa-push-challenge-push`, `mfa-push-list`, `mfa-otp-enrollment-qr`, `mfa-otp-enrollment-code`, `mfa-otp-challenge`, `mfa-voice-enrollment`, `mfa-voice-challenge`, `mfa-phone-challenge`, `mfa-phone-enrollment`, `mfa-webauthn-platform-enrollment`, `mfa-webauthn-roaming-enrollment`, `mfa-webauthn-platform-challenge`, `mfa-webauthn-roaming-challenge`, `mfa-webauthn-change-key-nickname`, `mfa-webauthn-enrollment-success`, `mfa-webauthn-error`, `mfa-webauthn-not-available-error`, `mfa-country-codes`, `mfa-sms-enrollment`, `mfa-sms-challenge`, `mfa-sms-list`, `mfa-email-challenge`, `mfa-email-list`, `mfa-recovery-code-enrollment`, `mfa-recovery-code-challenge`, `mfa-detect-browser-capabilities`, `mfa-enroll-result`, `mfa-login-options`, `mfa-begin-enroll-options`, `status`, `device-code-activation`, `device-code-activation-allowed`, `device-code-activation-denied`, `device-code-confirmation`, `email-verification-result`, `email-otp-challenge`, `organization-selection`, `organization-picker`, `accept-invitation`, `redeem-ticket`, `passkey-enrollment`, `passkey-enrollment-local`, `interstitial-captcha`. | ||
|
||
### Optional | ||
|
||
- `context_configuration` (Set of String) Context values to make available | ||
- `default_head_tags_disabled` (Boolean) Override Universal Login default head tags | ||
- `head_tags` (String) An array of head tags | ||
- `rendering_mode` (String) Rendering modeOptions are: `standard`, `advanced`. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `tenant` (String) Tenant ID | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# This resource can be imported using the prompt name and screen_name. | ||
# | ||
# As this is not a resource identifiable by an ID within the Auth0 Management API, | ||
# login can be imported using the prompt name and screen name using the format: | ||
# prompt_name:screen_name | ||
# | ||
# Example: | ||
terraform import auth0_prompt_screen_renderer "login-id:login-id" | ||
``` |
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 @@ | ||
# This resource can be imported using the prompt name and screen_name. | ||
# | ||
# As this is not a resource identifiable by an ID within the Auth0 Management API, | ||
# login can be imported using the prompt name and screen name using the format: | ||
# prompt_name:screen_name | ||
# | ||
# Example: | ||
terraform import auth0_prompt_screen_renderer "login-id:login-id" |
39 changes: 39 additions & 0 deletions
39
examples/resources/auth0_prompt_screen_renderer/resource.tf
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,39 @@ | ||
resource "auth0_prompt_screen_renderer" "prompt_screen_renderer" { | ||
prompt_type = "login-id" | ||
screen_name = "login-id" | ||
rendering_mode = "advanced" | ||
default_head_tags_disabled = false | ||
context_configuration = [ | ||
"branding.settings", | ||
"branding.themes.default", | ||
"client.logo_uri", | ||
"client.description", | ||
"client.metadata.key", | ||
"organization.display_name", | ||
"organization.branding", | ||
"organization.metadata.key", | ||
"screen.texts", | ||
"tenant.name", | ||
"tenant.friendly_name", | ||
"tenant.enabled_locales", | ||
"untrusted_data.submitted_form_data", | ||
"untrusted_data.authorization_params.login_hint", | ||
"untrusted_data.authorization_params.screen_hint", | ||
"untrusted_data.authorization_params.ui_locales", | ||
"untrusted_data.authorization_params.ext-.key", | ||
"transaction.connection.metadata.key" | ||
] | ||
head_tags = jsonencode([ | ||
{ | ||
attributes : { | ||
"async" : true, | ||
"defer" : true, | ||
"integrity" : [ | ||
"sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" | ||
], | ||
"src" : "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" | ||
}, | ||
tag : "script" | ||
} | ||
]) | ||
} |
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,54 @@ | ||
package prompt | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/auth0/go-auth0/management" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
|
||
"github.com/auth0/terraform-provider-auth0/internal/config" | ||
internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema" | ||
) | ||
|
||
// NewPromptScreenRenderDataSource creates a new data source to retrieve the prompt and screen settings`. | ||
func NewPromptScreenRenderDataSource() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: readPromptScreenRenderDataSource, | ||
Description: "Data source to retrieve a specific Auth0 prompt screen settings by `prompt_type` and `screen_name`", | ||
Schema: getPromptScreenRenderDataSourceSchema(), | ||
} | ||
} | ||
|
||
func getPromptScreenRenderDataSourceSchema() map[string]*schema.Schema { | ||
dataSourceSchema := internalSchema.TransformResourceToDataSource(NewPromptScreenRenderResource().Schema) | ||
internalSchema.SetExistingAttributesAsRequired(dataSourceSchema, "prompt_type", "screen_name") | ||
dataSourceSchema["prompt_type"].Description = "The type of prompt to customize." | ||
dataSourceSchema["prompt_type"].ValidateFunc = validation.StringInSlice(allowedPromptsSettingsRenderer, false) | ||
dataSourceSchema["screen_name"].Description = "The screen name associated with the prompt type." | ||
dataSourceSchema["screen_name"].ValidateFunc = validation.StringInSlice(allowedScreensSettingsRenderer, false) | ||
return dataSourceSchema | ||
} | ||
|
||
func readPromptScreenRenderDataSource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
api := meta.(*config.Config).GetAPI() | ||
|
||
prompt := management.PromptType(data.Get("prompt_type").(string)) | ||
screen := management.ScreenName(data.Get("screen_name").(string)) | ||
|
||
screenSettings, err := api.Prompt.ReadRendering(ctx, prompt, screen) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
data.SetId(fmt.Sprintf("%s:%s", prompt, screen)) | ||
|
||
if err := flattenPromptScreenSettings(data, screenSettings); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return diag.FromErr(err) | ||
} |
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,99 @@ | ||
package prompt_test | ||
|
||
import ( | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
|
||
"github.com/auth0/terraform-provider-auth0/internal/acctest" | ||
) | ||
|
||
const testAccPromptScreenRenderWithoutScreens = testAccGivenACustomDomain + testGivenABrandingTemplate + ` | ||
data "auth0_prompt_screen_renderer" "prompt_screen_render" { | ||
prompt_type = "login-passwordless" | ||
} | ||
` | ||
const testAccPromptScreenRenderInvalid = ` | ||
data "auth0_prompt_screen_renderer" "prompt_screen_render" { | ||
prompt_type = "login-xxxxx" | ||
screen_name = "login-passwordless-email-code" | ||
} | ||
` | ||
|
||
const testAccPromptScreenRenderData = ` | ||
resource "auth0_prompt_screen_renderer" "prompt_screen_render" { | ||
prompt_type = "login-passwordless" | ||
screen_name = "login-passwordless-email-code" | ||
rendering_mode = "advanced" | ||
context_configuration = [ | ||
"branding.settings", | ||
"branding.themes.default", | ||
"client.logo_uri", | ||
"client.description", | ||
"organization.display_name", | ||
"organization.branding", | ||
"screen.texts", | ||
"tenant.name", | ||
"tenant.friendly_name", | ||
"tenant.enabled_locales", | ||
"untrusted_data.submitted_form_data", | ||
"untrusted_data.authorization_params.ui_locales", | ||
"untrusted_data.authorization_params.login_hint", | ||
"untrusted_data.authorization_params.screen_hint" | ||
] | ||
head_tags = jsonencode([ | ||
{ | ||
attributes: { | ||
"async": true, | ||
"defer": true, | ||
"integrity": [ | ||
"sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" | ||
], | ||
"src": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" | ||
}, | ||
tag: "script" | ||
} | ||
]) | ||
} | ||
data "auth0_prompt_screen_renderer" "prompt_screen_render" { | ||
depends_on = [ auth0_prompt_screen_renderer.prompt_screen_render ] | ||
prompt_type = auth0_prompt_screen_renderer.prompt_screen_render.prompt_type | ||
screen_name = auth0_prompt_screen_renderer.prompt_screen_render.screen_name | ||
} | ||
` | ||
|
||
func TestAccDataPromptScreenRender(t *testing.T) { | ||
acctest.Test(t, resource.TestCase{ | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: `data "auth0_prompt_screen_renderer" "prompt_screen_render" { }`, | ||
ExpectError: regexp.MustCompile("Error: Missing required argument"), | ||
}, | ||
{ | ||
Config: testAccPromptScreenRenderWithoutScreens, | ||
ExpectError: regexp.MustCompile("Error: Missing required argument"), | ||
}, | ||
{ | ||
Config: testAccPromptScreenRenderInvalid, | ||
ExpectError: regexp.MustCompile("expected prompt_type to be one of"), | ||
}, | ||
{ | ||
Config: testAccPromptScreenRenderData, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("auth0_prompt_screen_renderer.prompt_screen_render", "prompt_type", "login-passwordless"), | ||
resource.TestCheckResourceAttr("auth0_prompt_screen_renderer.prompt_screen_render", "screen_name", "login-passwordless-email-code"), | ||
resource.TestCheckResourceAttr("auth0_prompt_screen_renderer.prompt_screen_render", "rendering_mode", "advanced"), | ||
resource.TestCheckResourceAttr("auth0_prompt_screen_renderer.prompt_screen_render", "context_configuration.#", "14"), | ||
resource.TestCheckResourceAttr("data.auth0_prompt_screen_renderer.prompt_screen_render", "prompt_type", "login-passwordless"), | ||
resource.TestCheckResourceAttr("data.auth0_prompt_screen_renderer.prompt_screen_render", "screen_name", "login-passwordless-email-code"), | ||
resource.TestCheckResourceAttr("data.auth0_prompt_screen_renderer.prompt_screen_render", "rendering_mode", "advanced"), | ||
resource.TestCheckResourceAttr("data.auth0_prompt_screen_renderer.prompt_screen_render", "context_configuration.#", "14"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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.