Skip to content

Commit f156db8

Browse files
Add support for all languages for Universal Login (#1016)
* Fetch list of languages from CDN instead of hardcoding them * Updated linting --------- Co-authored-by: KunalOfficial <[email protected]>
1 parent 24105b4 commit f156db8

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

docs/resources/prompt_custom_text.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ resource "auth0_prompt_custom_text" "example" {
4848
### Required
4949

5050
- `body` (String) JSON containing the custom texts. You can check the options for each prompt [here](https://auth0.com/docs/customize/universal-login-pages/customize-login-text-prompts#prompt-values).
51-
- `language` (String) Language of the custom text. Options include: `ar`, `bg`, `bs`, `ca-ES`, `cs`, `cy`, `da`, `de`, `el`, `en`, `es`, `et`, `eu-ES`, `fi`, `fr`, `fr-CA`, `fr-FR`, `gl-ES`, `he`, `hi`, `hr`, `hu`, `id`, `is`, `it`, `ja`, `ko`, `lt`, `lv`, `nb`, `nl`, `nn`, `no`, `pl`, `pt`, `pt-BR`, `pt-PT`, `ro`, `ru`, `sk`, `sl`, `sr`, `sv`, `th`, `tr`, `uk`, `vi`, `zh-CN`, `zh-TW`.
51+
- `language` (String) Language of the custom text. Options include: `ar`, `ar-EG`, `ar-SA`, `az`, `bg`, `bs`, `ca-ES`, `cs`, `cy`, `da`, `de`, `el`, `en`, `es`, `es-AR`, `es-MX`, `et`, `eu-ES`, `fa`, `fi`, `fr`, `fr-CA`, `fr-FR`, `gl-ES`, `he`, `hi`, `hr`, `hu`, `hy`, `id`, `is`, `it`, `ja`, `ko`, `lt`, `lv`, `ms`, `nb`, `nl`, `nn`, `no`, `pl`, `pt`, `pt-BR`, `pt-PT`, `ro`, `ru`, `sk`, `sl`, `sq`, `sr`, `sv`, `th`, `tl`, `tr`, `uk`, `ur`, `vi`, `zh-CN`, `zh-HK`, `zh-TW`.
5252
- `prompt` (String) The term `prompt` is used to refer to a specific step in the login flow. Options include: `captcha`, `common`, `consent`, `custom-form`, `customized-consent`, `device-flow`, `email-otp-challenge`, `email-verification`, `invitation`, `login`, `login-email-verification`, `login-id`, `login-password`, `login-passwordless`, `logout`, `mfa`, `mfa-email`, `mfa-otp`, `mfa-phone`, `mfa-push`, `mfa-recovery-code`, `mfa-sms`, `mfa-voice`, `mfa-webauthn`, `organizations`, `passkeys`, `phone-identifier-challenge`, `phone-identifier-enrollment`, `reset-password`, `signup`, `signup-id`, `signup-password`, `status`.
5353

5454
### Read-Only

internal/auth0/prompt/resource_custom_text.go

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package prompt
33
import (
44
"context"
55
"encoding/json"
6+
"io"
7+
"net/http"
68
"strings"
9+
"time"
710

811
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
912
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -15,6 +18,44 @@ import (
1518
internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema"
1619
)
1720

21+
const languagesURL = "https://cdn.auth0.com/ulp/react-components/development/languages/available-languages.json"
22+
23+
func fetchLanguages() []string {
24+
fallbackAvailableLanguages := []string{
25+
"ar", "bg", "bs", "ca-ES", "cs", "cy", "da", "de", "el", "en", "es", "et", "eu-ES", "fi", "fr", "fr-CA", "fr-FR", "gl-ES", "he", "hi", "hr",
26+
"hu", "id", "is", "it", "ja", "ko", "lt", "lv", "nb", "nl", "nn", "no", "pl", "pt", "pt-BR", "pt-PT", "ro", "ru", "sk",
27+
"sl", "sr", "sv", "th", "tr", "uk", "vi", "zh-CN", "zh-TW",
28+
}
29+
30+
client := http.Client{
31+
Timeout: 10 * time.Second, // Set a timeout for the HTTP request.
32+
}
33+
34+
resp, err := client.Get(languagesURL)
35+
if err != nil {
36+
return fallbackAvailableLanguages
37+
}
38+
defer func(Body io.ReadCloser) {
39+
err = Body.Close()
40+
}(resp.Body)
41+
42+
if resp.StatusCode != http.StatusOK {
43+
return fallbackAvailableLanguages
44+
}
45+
46+
var retrievedLanguages []string
47+
decoder := json.NewDecoder(resp.Body)
48+
if err := decoder.Decode(&retrievedLanguages); err != nil {
49+
return fallbackAvailableLanguages
50+
}
51+
52+
if len(retrievedLanguages) == 0 {
53+
return fallbackAvailableLanguages
54+
}
55+
56+
return retrievedLanguages
57+
}
58+
1859
var (
1960
availablePrompts = []string{
2061
"captcha", "common", "consent", "custom-form", "customized-consent", "device-flow", "email-otp-challenge",
@@ -23,11 +64,8 @@ var (
2364
"mfa-sms", "mfa-voice", "mfa-webauthn", "organizations", "passkeys", "phone-identifier-challenge",
2465
"phone-identifier-enrollment", "reset-password", "signup", "signup-id", "signup-password", "status",
2566
}
26-
availableLanguages = []string{
27-
"ar", "bg", "bs", "ca-ES", "cs", "cy", "da", "de", "el", "en", "es", "et", "eu-ES", "fi", "fr", "fr-CA", "fr-FR", "gl-ES", "he", "hi", "hr",
28-
"hu", "id", "is", "it", "ja", "ko", "lt", "lv", "nb", "nl", "nn", "no", "pl", "pt", "pt-BR", "pt-PT", "ro", "ru", "sk",
29-
"sl", "sr", "sv", "th", "tr", "uk", "vi", "zh-CN", "zh-TW",
30-
}
67+
68+
availableLanguages = fetchLanguages()
3169
)
3270

3371
// NewCustomTextResource will return a new auth0_prompt_custom_text resource.

0 commit comments

Comments
 (0)