-
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 Self Service Profile SSO (#1008)
* Added schema, test cases and documentation for Self Service Profile SSO * Added test recordings * minor update on read
- Loading branch information
1 parent
1d8a8e8
commit 6b39f7c
Showing
14 changed files
with
1,249 additions
and
0 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,60 @@ | ||
--- | ||
page_title: "Data Source: auth0_self_service_profile" | ||
description: |- | ||
Data source to retrieve a specific Auth0 Self-Service Profile by id | ||
--- | ||
|
||
# Data Source: auth0_self_service_profile | ||
|
||
Data source to retrieve a specific Auth0 Self-Service Profile by `id` | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# An Auth0 Self-Service- Profile loaded using it's ID. | ||
data "auth0_self_service_profile" "auth0_self_service_profile" { | ||
id = "some-profile-id" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `id` (String) The id of the Self Service Profile | ||
|
||
### Read-Only | ||
|
||
- `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. | ||
- `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)) | ||
|
||
<a id="nestedatt--branding"></a> | ||
### Nested Schema for `branding` | ||
|
||
Read-Only: | ||
|
||
- `colors` (List of Object) (see [below for nested schema](#nestedobjatt--branding--colors)) | ||
- `logo_url` (String) | ||
|
||
<a id="nestedobjatt--branding--colors"></a> | ||
### Nested Schema for `branding.colors` | ||
|
||
Read-Only: | ||
|
||
- `primary` (String) | ||
|
||
|
||
|
||
<a id="nestedatt--user_attributes"></a> | ||
### Nested Schema for `user_attributes` | ||
|
||
Read-Only: | ||
|
||
- `description` (String) | ||
- `is_optional` (Boolean) | ||
- `name` (String) | ||
|
||
|
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,77 @@ | ||
--- | ||
page_title: "Resource: auth0_self_service_profile" | ||
description: |- | ||
With this resource, you can create and manage Self-Service Profile for a tenant. | ||
--- | ||
|
||
# Resource: auth0_self_service_profile | ||
|
||
With this resource, you can create and manage Self-Service Profile for a tenant. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "auth0_self_service_profile" "my_self_service_profile" { | ||
user_attributes { | ||
name = "sample-name" | ||
description = "sample-description" | ||
is_optional = true | ||
} | ||
branding { | ||
logo_url = "https://mycompany.org/v2/logo.png" | ||
colors { | ||
primary = "#0059d6" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `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)) | ||
- `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 | ||
|
||
- `created_at` (String) The ISO 8601 formatted date the profile was created. | ||
- `id` (String) The ID of this resource. | ||
- `updated_at` (String) The ISO 8601 formatted date the profile was updated. | ||
|
||
<a id="nestedblock--branding"></a> | ||
### Nested Schema for `branding` | ||
|
||
Optional: | ||
|
||
- `colors` (Block List, Max: 1) Configuration settings for colors for branding. (see [below for nested schema](#nestedblock--branding--colors)) | ||
- `logo_url` (String) URL of logo to display on login page. | ||
|
||
<a id="nestedblock--branding--colors"></a> | ||
### Nested Schema for `branding.colors` | ||
|
||
Optional: | ||
|
||
- `primary` (String) Primary button background color in hexadecimal. | ||
|
||
|
||
|
||
<a id="nestedblock--user_attributes"></a> | ||
### Nested Schema for `user_attributes` | ||
|
||
Required: | ||
|
||
- `description` (String) A human readable description of the attribute. | ||
- `is_optional` (Boolean) Indicates if this attribute is optional or if it has to be provided by the customer for the application to function. | ||
- `name` (String) Attribute’s name on Auth0 side | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# This resource can be imported using the id | ||
# Example: | ||
terraform import auth0_self_service_profile.id "ssp_32oi5unksja93124" | ||
``` |
4 changes: 4 additions & 0 deletions
4
examples/data-sources/auth0_self_service_profile/data-source.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,4 @@ | ||
# An Auth0 Self-Service- Profile loaded using it's ID. | ||
data "auth0_self_service_profile" "auth0_self_service_profile" { | ||
id = "some-profile-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,3 @@ | ||
# This resource can be imported using the id | ||
# Example: | ||
terraform import auth0_self_service_profile.id "ssp_32oi5unksja93124" |
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,14 @@ | ||
resource "auth0_self_service_profile" "my_self_service_profile" { | ||
user_attributes { | ||
name = "sample-name" | ||
description = "sample-description" | ||
is_optional = true | ||
} | ||
branding { | ||
logo_url = "https://mycompany.org/v2/logo.png" | ||
colors { | ||
primary = "#0059d6" | ||
} | ||
} | ||
} | ||
|
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,43 @@ | ||
package selfserviceprofile | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/auth0/terraform-provider-auth0/internal/config" | ||
internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema" | ||
) | ||
|
||
// NewDataSource will return a new auth0_self_service_profile data source. | ||
func NewDataSource() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: readSelfServiceProfileForDataSource, | ||
Description: "Data source to retrieve a specific Auth0 Self-Service Profile by `id`", | ||
Schema: dataSourceSchema(), | ||
} | ||
} | ||
|
||
func dataSourceSchema() map[string]*schema.Schema { | ||
dataSourceSchema := internalSchema.TransformResourceToDataSource(NewResource().Schema) | ||
dataSourceSchema["id"] = &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The ID of the Self Service Profile.", | ||
} | ||
dataSourceSchema["id"].Description = "The id of the Self Service Profile " | ||
return dataSourceSchema | ||
} | ||
|
||
func readSelfServiceProfileForDataSource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
api := meta.(*config.Config).GetAPI() | ||
id := data.Get("id").(string) | ||
data.SetId(id) | ||
ssp, err := api.SelfServiceProfile.Read(ctx, data.Id()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
err = flattenSelfServiceProfile(data, ssp) | ||
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 selfserviceprofile_test | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
|
||
"github.com/auth0/terraform-provider-auth0/internal/acctest" | ||
) | ||
|
||
const testAGivenSelfServiceProfile = ` | ||
resource "auth0_self_service_profile" "my_self_service_profile" { | ||
user_attributes { | ||
name = "sample-name-{{.testName}}" | ||
description = "sample-description" | ||
is_optional = true | ||
} | ||
branding { | ||
logo_url = "https://mycompany.org/v2/logo.png" | ||
colors { | ||
primary = "#0059d6" | ||
} | ||
} | ||
} | ||
` | ||
|
||
const testDataResourceWithoutID = testAGivenSelfServiceProfile + ` | ||
data "auth0_self_service_profile" "my_profile" { | ||
depends_on = [ auth0_self_service_profile.my_self_service_profile ] | ||
}` | ||
|
||
const testDataResourceWithValidID = testAGivenSelfServiceProfile + ` | ||
data "auth0_self_service_profile" "my_profile" { | ||
depends_on = [ auth0_self_service_profile.my_self_service_profile ] | ||
id = auth0_self_service_profile.my_self_service_profile.id | ||
} | ||
` | ||
|
||
const testDataResourceWithInvalidID = testAGivenSelfServiceProfile + ` | ||
data "auth0_self_service_profile" "my_profile" { | ||
depends_on = [ auth0_self_service_profile.my_self_service_profile ] | ||
id = "ssp_bskks8aGbiq7qS13umnuvX" | ||
} | ||
` | ||
|
||
func TestSelfServiceDataSourceResourceRequiredId(t *testing.T) { | ||
resource.UnitTest(t, resource.TestCase{ | ||
ProviderFactories: acctest.TestFactories(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataResourceWithoutID, | ||
ExpectError: regexp.MustCompile("The argument \"id\" is required, but no definition was found."), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestSelfServiceDataSourceResource(t *testing.T) { | ||
acctest.Test(t, resource.TestCase{ | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: acctest.ParseTestName(testDataResourceWithInvalidID, t.Name()), | ||
ExpectError: regexp.MustCompile( | ||
`Error: 404 Not Found`, | ||
), | ||
}, | ||
{ | ||
Config: acctest.ParseTestName(testDataResourceWithValidID, t.Name()), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckTypeSetElemNestedAttrs( | ||
"data.auth0_self_service_profile.my_profile", | ||
"user_attributes.*", | ||
map[string]string{ | ||
"name": fmt.Sprintf("sample-name-%s", t.Name()), | ||
"description": "sample-description", | ||
"is_optional": "true", | ||
}, | ||
), | ||
resource.TestCheckTypeSetElemNestedAttrs( | ||
"data.auth0_self_service_profile.my_profile", | ||
"branding.*", | ||
map[string]string{ | ||
"logo_url": "https://mycompany.org/v2/logo.png", | ||
}, | ||
), | ||
resource.TestCheckTypeSetElemNestedAttrs( | ||
"data.auth0_self_service_profile.my_profile", | ||
"branding.*.colors.*", | ||
map[string]string{ | ||
"primary": "#0059d6", | ||
}, | ||
), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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,68 @@ | ||
package selfserviceprofile | ||
|
||
import ( | ||
"github.com/auth0/go-auth0/management" | ||
"github.com/hashicorp/go-cty/cty" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/auth0/terraform-provider-auth0/internal/value" | ||
) | ||
|
||
func expandSelfServiceProfiles(data *schema.ResourceData) *management.SelfServiceProfile { | ||
cfg := data.GetRawConfig() | ||
|
||
return &management.SelfServiceProfile{ | ||
UserAttributes: expandSelfServiceProfileUserAttributes(cfg.GetAttr("user_attributes")), | ||
Branding: expandBranding(cfg.GetAttr("branding")), | ||
} | ||
} | ||
|
||
func expandSelfServiceProfileUserAttributes(userAttr cty.Value) []*management.SelfServiceProfileUserAttributes { | ||
if userAttr.IsNull() { | ||
return nil | ||
} | ||
|
||
SelfServiceProfileUserAttributes := make([]*management.SelfServiceProfileUserAttributes, 0) | ||
|
||
userAttr.ForEachElement(func(_ cty.Value, attr cty.Value) (stop bool) { | ||
SelfServiceProfileUserAttributes = append(SelfServiceProfileUserAttributes, &management.SelfServiceProfileUserAttributes{ | ||
Name: value.String(attr.GetAttr("name")), | ||
Description: value.String(attr.GetAttr("description")), | ||
IsOptional: value.Bool(attr.GetAttr("is_optional")), | ||
}) | ||
return stop | ||
}) | ||
|
||
return SelfServiceProfileUserAttributes | ||
} | ||
|
||
func expandBranding(config cty.Value) *management.Branding { | ||
var branding management.Branding | ||
|
||
config.ForEachElement(func(_ cty.Value, b cty.Value) (stop bool) { | ||
branding.LogoURL = value.String(b.GetAttr("logo_url")) | ||
branding.Colors = expandBrandingColors(b.GetAttr("colors")) | ||
return stop | ||
}) | ||
|
||
if branding == (management.Branding{}) { | ||
return nil | ||
} | ||
|
||
return &branding | ||
} | ||
|
||
func expandBrandingColors(config cty.Value) *management.BrandingColors { | ||
var brandingColors management.BrandingColors | ||
|
||
config.ForEachElement(func(_ cty.Value, colors cty.Value) (stop bool) { | ||
brandingColors.Primary = value.String(colors.GetAttr("primary")) | ||
return stop | ||
}) | ||
|
||
if brandingColors == (management.BrandingColors{}) { | ||
return nil | ||
} | ||
|
||
return &brandingColors | ||
} |
Oops, something went wrong.