Skip to content

Commit

Permalink
SSO v2 changes (#1075)
Browse files Browse the repository at this point in the history
* SSO v2 changes

* naming fixes

* Dummy commit

* Updated go mod

* updated recording

* Updated var name to fix lint issue

* Added example for auth0_self_service_profile_custom_text

* Added docs and examples

* Updated docs

* Updates

* Addressed review comments
  • Loading branch information
duedares-rvj authored Nov 18, 2024
1 parent de227d1 commit ec2597c
Show file tree
Hide file tree
Showing 21 changed files with 1,469 additions and 132 deletions.
3 changes: 3 additions & 0 deletions docs/data-sources/self_service_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ data "auth0_self_service_profile" "auth0_self_service_profile" {

### Read-Only

- `allowed_strategies` (Set of String) List of IdP strategies that will be shown to users during the Self-Service SSO flow.
- `branding` (List of Object) Field can be used to customize the look and feel of the wizard. (see [below for nested schema](#nestedatt--branding))
- `created_at` (String) The ISO 8601 formatted date the profile was created.
- `description` (String) The description of the self-service Profile
- `name` (String) The name of the self-service Profile
- `updated_at` (String) The ISO 8601 formatted date the profile was updated.
- `user_attributes` (List of Object) This array stores the mapping information that will be shown to the user during the SS-SSO flow. The user will be prompted to map the attributes on their identity provider to ensure the specified attributes get passed to Auth0. (see [below for nested schema](#nestedatt--user_attributes))

Expand Down
6 changes: 6 additions & 0 deletions docs/resources/self_service_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ resource "auth0_self_service_profile" "my_self_service_profile" {
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the self-service Profile

### Optional

- `allowed_strategies` (Set of String) List of IdP strategies that will be shown to users during the Self-Service SSO flow.
- `branding` (Block List, Max: 1) Field can be used to customize the look and feel of the wizard. (see [below for nested schema](#nestedblock--branding))
- `description` (String) The description of the self-service Profile
- `user_attributes` (Block List, Max: 20) This array stores the mapping information that will be shown to the user during the SS-SSO flow. The user will be prompted to map the attributes on their identity provider to ensure the specified attributes get passed to Auth0. (see [below for nested schema](#nestedblock--user_attributes))

### Read-Only
Expand Down
51 changes: 51 additions & 0 deletions docs/resources/self_service_profile_custom_text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
page_title: "Resource: auth0_self_service_profile_custom_text"
description: |-
With this resource, you can set custom text for Self-Service Profile
---

# Resource: auth0_self_service_profile_custom_text

With this resource, you can set custom text for Self-Service Profile

## Example Usage

```terraform
resource "auth0_self_service_profile_custom_text" "sso_custom_text" {
sso_id = "some-sso-id"
language = "en"
page = "get-started"
body = jsonencode(
{
"introduction" : "Welcome! With only a few steps you'll be able to setup your new custom text."
}
)
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `body` (String) The list of text keys and values to customize the self-service SSO page. Values can be plain text or rich HTML content limited to basic styling tags and hyperlinks
- `language` (String) The language of the custom text
- `page` (String) The page where the custom text is shown
- `sso_id` (String) The id of the self-service profile

### Read-Only

- `id` (String) The ID of this resource.

## Import

Import is supported using the following syntax:

```shell
# This resource can be imported by specifying the
# sso-profile-id, language and page separated by "::" (note the double colon)
# <sso-profile-id>::<language>::<page>
#
# Example
terraform import auth0_self_service_profile_custom_text.example "some-sso-id::en::get-started"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This resource can be imported by specifying the
# sso-profile-id, language and page separated by "::" (note the double colon)
# <sso-profile-id>::<language>::<page>
#
# Example
terraform import auth0_self_service_profile_custom_text.example "some-sso-id::en::get-started"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "auth0_self_service_profile_custom_text" "sso_custom_text" {
sso_id = "some-sso-id"
language = "en"
page = "get-started"
body = jsonencode(
{
"introduction" : "Welcome! With only a few steps you'll be able to setup your new custom text."
}
)
}

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.5

require (
github.com/PuerkitoBio/rehttp v1.4.0
github.com/auth0/go-auth0 v1.11.2
github.com/auth0/go-auth0 v1.11.3-0.20241113184128-ddfd407304f5
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-multierror v1.1.1
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/auth0/go-auth0 v1.11.2 h1:WLh0K3iau5d5mCt08vIvynOM5jCRmv/WJDH8FBo4Fu4=
github.com/auth0/go-auth0 v1.11.2/go.mod h1:VyYseHsdB4s9jmfBqoxnzJTvZr0w17ZJ5kjNdA+ag9Y=
github.com/auth0/go-auth0 v1.11.3-0.20241111092011-46578faea3fc h1:D3Com1bbzf4tCWdiAgM8i/tDsIGn/RFFl/KpnFP81uQ=
github.com/auth0/go-auth0 v1.11.3-0.20241111092011-46578faea3fc/go.mod h1:vmYy3IH8KkbJb+kxuAX1TBGUlhR3HFNsD+7F518qf90=
github.com/auth0/go-auth0 v1.11.3-0.20241111092326-a0cf7a08f44d h1:SI0EVpcFhqz5a/WhMarz24d1T+mXoh6GWOU3NPrL+uY=
github.com/auth0/go-auth0 v1.11.3-0.20241111092326-a0cf7a08f44d/go.mod h1:vmYy3IH8KkbJb+kxuAX1TBGUlhR3HFNsD+7F518qf90=
github.com/auth0/go-auth0 v1.11.3-0.20241111093533-5387e0cfb42b h1:Rmq9lf4ijBK0LBY60FQNE+iVzvxeY3m7+BO9tdtLsiU=
github.com/auth0/go-auth0 v1.11.3-0.20241111093533-5387e0cfb42b/go.mod h1:vmYy3IH8KkbJb+kxuAX1TBGUlhR3HFNsD+7F518qf90=
github.com/auth0/go-auth0 v1.11.3-0.20241113184128-ddfd407304f5 h1:v2NO2cz8Orj2I3WxqkGI8kHNW46wTef6esYDLQnU/gc=
github.com/auth0/go-auth0 v1.11.3-0.20241113184128-ddfd407304f5/go.mod h1:vmYy3IH8KkbJb+kxuAX1TBGUlhR3HFNsD+7F518qf90=
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48=
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0/go.mod h1:6L7zgvqo0idzI7IO8de6ZC051AfXb5ipkIJ7bIA2tGA=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
Expand Down
3 changes: 3 additions & 0 deletions internal/auth0/selfserviceprofile/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (

const testAGivenSelfServiceProfile = `
resource "auth0_self_service_profile" "my_self_service_profile" {
name = "my-sso-profile"
description = "sample description"
allowed_strategies = ["oidc", "samlp"]
user_attributes {
name = "sample-name-{{.testName}}"
description = "sample-description"
Expand Down
7 changes: 5 additions & 2 deletions internal/auth0/selfserviceprofile/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ func expandSelfServiceProfiles(data *schema.ResourceData) *management.SelfServic
cfg := data.GetRawConfig()

return &management.SelfServiceProfile{
UserAttributes: expandSelfServiceProfileUserAttributes(cfg.GetAttr("user_attributes")),
Branding: expandBranding(cfg.GetAttr("branding")),
Name: value.String(cfg.GetAttr("name")),
Description: value.String(cfg.GetAttr("description")),
AllowedStrategies: value.Strings(cfg.GetAttr("allowed_strategies")),
UserAttributes: expandSelfServiceProfileUserAttributes(cfg.GetAttr("user_attributes")),
Branding: expandBranding(cfg.GetAttr("branding")),
}
}

Expand Down
32 changes: 32 additions & 0 deletions internal/auth0/selfserviceprofile/flatten.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package selfserviceprofile

import (
"bytes"
"encoding/json"
"fmt"

"github.com/auth0/go-auth0/management"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -54,3 +58,31 @@ func flattenBrandingColors(brandingColors *management.BrandingColors) []interfac
},
}
}

func flattenSSOCustomText(data *schema.ResourceData, customText map[string]interface{}) error {
body, err := marshalCustomTextBody(customText)
if err != nil {
return err
}

return data.Set("body", body)
}

func marshalCustomTextBody(b map[string]interface{}) (string, error) {
if b == nil {
return "{}", nil
}

bodyBytes, err := json.Marshal(b)
if err != nil {
return "", fmt.Errorf("failed to serialize the custom texts to JSON: %w", err)
}

var buffer bytes.Buffer
const jsonIndentation = " "
if err := json.Indent(&buffer, bodyBytes, "", jsonIndentation); err != nil {
return "", fmt.Errorf("failed to format the custom texts JSON: %w", err)
}

return buffer.String(), nil
}
24 changes: 24 additions & 0 deletions internal/auth0/selfserviceprofile/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ func NewResource() *schema.Resource {
},
Description: "With this resource, you can create and manage Self-Service Profile for a tenant.",
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
Description: "The name of the self-service Profile",
},
"description": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 140),
Description: "The description of the self-service Profile",
},
"user_attributes": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -86,6 +98,18 @@ func NewResource() *schema.Resource {
},
},
},
"allowed_strategies": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"oidc", "samlp", "waad", "google-apps",
"adfs", "okta", "keycloak-samlp", "pingfederate"},
false),
},
Description: "List of IdP strategies that will be shown to users during the Self-Service SSO flow.",
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Expand Down
111 changes: 111 additions & 0 deletions internal/auth0/selfserviceprofile/resource_custom_text.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package selfserviceprofile

import (
"context"
"encoding/json"

"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/structure"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/auth0/terraform-provider-auth0/internal/config"
internalError "github.com/auth0/terraform-provider-auth0/internal/error"
internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema"
)

// NewCustomTextResource will return a new auth0_self_service_profile_custom_text resource.
func NewCustomTextResource() *schema.Resource {
return &schema.Resource{
CreateContext: createCustomTextForSSOProfile,
ReadContext: readCustomTextForSSOProfile,
UpdateContext: updateCustomTextForSSOProfile,
DeleteContext: deleteCustomTextForSSOProfile,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Description: "With this resource, you can set custom text for Self-Service Profile",
Schema: map[string]*schema.Schema{
"sso_id": {
Type: schema.TypeString,
ForceNew: true,
Required: true,
Description: "The id of the self-service profile",
},
"language": {
Type: schema.TypeString,
Required: true,
Description: "The language of the custom text",
},
"page": {
Type: schema.TypeString,
Required: true,
Description: "The page where the custom text is shown",
},
"body": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: structure.SuppressJsonDiff,
Description: "The list of text keys and values to customize the self-service SSO page. " +
"Values can be plain text or rich HTML content limited to basic styling tags and hyperlinks",
},
},
}
}

func createCustomTextForSSOProfile(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
id := data.Get("sso_id").(string)
language := data.Get("language").(string)
page := data.Get("page").(string)

internalSchema.SetResourceGroupID(data, id, language, page)

return updateCustomTextForSSOProfile(ctx, data, meta)
}

func readCustomTextForSSOProfile(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

customText, err := api.SelfServiceProfile.GetCustomText(ctx,
data.Get("sso_id").(string),
data.Get("language").(string),
data.Get("page").(string))
if err != nil {
return diag.FromErr(internalError.HandleAPIError(data, err))
}

return diag.FromErr(flattenSSOCustomText(data, customText))
}

func updateCustomTextForSSOProfile(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

id := data.Get("sso_id").(string)
language := data.Get("language").(string)
page := data.Get("page").(string)
body := data.Get("body").(string)

if body == "" {
return nil
}

var payload map[string]interface{}
if err := json.Unmarshal([]byte(body), &payload); err != nil {
return diag.FromErr(err)
}

if err := api.SelfServiceProfile.SetCustomText(ctx, id, language, page, payload); err != nil {
return diag.FromErr(err)
}

return readCustomTextForSSOProfile(ctx, data, meta)
}

func deleteCustomTextForSSOProfile(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
if err := data.Set("body", "{}"); err != nil {
return diag.FromErr(err)
}

return updateCustomTextForSSOProfile(ctx, data, meta)
}
Loading

0 comments on commit ec2597c

Please sign in to comment.