Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Implements the native_social_login stanza on the Client API. #453

Merged
merged 4 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.25.1

ENHANCEMENTS:

* resource/client: Add the `native_social_login` field for native `app_types` ([#453](https://github.com/alexkappa/terraform-provider-auth0/pull/453))

NOTES:

* Fix role docs [#398](https://github.com/alexkappa/terraform-provider-auth0/pull/398)

## 0.25.0

ENHANCEMENTS:
Expand Down
76 changes: 76 additions & 0 deletions auth0/resource_auth0_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,42 @@ func newClient() *schema.Resource {
v.IsURLWithNoFragment,
),
},
"native_social_login": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"apple": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
},
},
},
},
"facebook": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
},
},
},
},
},
},
},
"refresh_token": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -595,6 +631,7 @@ func readClient(d *schema.ResourceData, m interface{}) error {
d.Set("custom_login_page", c.CustomLoginPage)
d.Set("form_template", c.FormTemplate)
d.Set("token_endpoint_auth_method", c.TokenEndpointAuthMethod)
d.Set("native_social_login", flattenCustomSocialConfiguration(c.NativeSocialLogin))
d.Set("jwt_configuration", flattenClientJwtConfiguration(c.JWTConfiguration))
d.Set("refresh_token", flattenClientRefreshTokenConfiguration(c.RefreshToken))
d.Set("encryption_key", c.EncryptionKey)
Expand Down Expand Up @@ -747,6 +784,24 @@ func expandClient(d *schema.ResourceData) *management.Client {
}
}

List(d, "native_social_login").Elem(func(d ResourceData) {
c.NativeSocialLogin = &management.ClientNativeSocialLogin{}

List(d, "apple").Elem(func(d ResourceData) {
m := make(MapData)
m.Set("enabled", Bool(d, "enabled"))

c.NativeSocialLogin.Apple = m
})

List(d, "facebook").Elem(func(d ResourceData) {
m := make(MapData)
m.Set("enabled", Bool(d, "enabled"))

c.NativeSocialLogin.Facebook = m
})
})

List(d, "mobile").Elem(func(d ResourceData) {

c.Mobile = make(map[string]interface{})
Expand Down Expand Up @@ -820,6 +875,27 @@ func clientHasChange(c *management.Client) bool {
return c.String() != "{}"
}

func flattenCustomSocialConfiguration(customSocial *management.ClientNativeSocialLogin) []interface{} {
if customSocial != nil {
m := make(map[string]interface{})

if customSocial.Apple != nil {
m["apple"] = map[string]interface{}{
"enabled": customSocial.Apple["enabled"],
}
}
if customSocial.Facebook != nil {
m["facebook"] = map[string]interface{}{
"enabled": customSocial.Facebook["enabled"],
}
}

return []interface{}{m}
}

return nil
}

func flattenClientJwtConfiguration(jwt *management.ClientJWTConfiguration) []interface{} {
m := make(map[string]interface{})
if jwt != nil {
Expand Down
57 changes: 56 additions & 1 deletion auth0/resource_auth0_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"strings"
"testing"

"github.com/alexkappa/terraform-provider-auth0/auth0/internal/random"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"

"github.com/alexkappa/terraform-provider-auth0/auth0/internal/random"

"gopkg.in/auth0.v5/management"
)

Expand Down Expand Up @@ -379,6 +380,8 @@ func TestAccClientMobile(t *testing.T) {
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.app_package_name", "com.example"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.sha256_cert_fingerprints.#", "1"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.sha256_cert_fingerprints.0", "DE:AD:BE:EF"),
resource.TestCheckResourceAttr("auth0_client.my_client", "native_social_login.0.apple.0.enabled", "true"),
resource.TestCheckResourceAttr("auth0_client.my_client", "native_social_login.0.facebook.0.enabled", "false"),
),
},
{
Expand All @@ -387,6 +390,15 @@ func TestAccClientMobile(t *testing.T) {
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.#", "1"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.app_package_name", "com.example"),
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.sha256_cert_fingerprints.#", "0"),
resource.TestCheckResourceAttr("auth0_client.my_client", "native_social_login.0.apple.0.enabled", "false"),
resource.TestCheckResourceAttr("auth0_client.my_client", "native_social_login.0.facebook.0.enabled", "true"),
),
},
{
// This just makes sure that you can change the type (where native_social_login cannot be set)
Config: random.Template(testAccClientConfigMobileUpdateNonMobile, rand),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "app_type", "non_interactive"),
),
},
},
Expand All @@ -397,11 +409,24 @@ const testAccClientConfigMobile = `

resource "auth0_client" "my_client" {
name = "Acceptance Test - Mobile - {{.random}}"
app_type = "native"
mobile {
android {
app_package_name = "com.example"
sha256_cert_fingerprints = ["DE:AD:BE:EF"]
}
ios {
team_id = "9JA89QQLNQ"
app_bundle_identifier = "com.my.bundle.id"
}
}
native_social_login {
apple {
enabled = true
}
facebook {
enabled = false
}
}
}
`
Expand All @@ -410,11 +435,41 @@ const testAccClientConfigMobileUpdate = `

resource "auth0_client" "my_client" {
name = "Acceptance Test - Mobile - {{.random}}"
app_type = "native"
mobile {
android {
app_package_name = "com.example"
sha256_cert_fingerprints = []
}
ios {
team_id = "1111111111"
app_bundle_identifier = "com.my.auth0.bundle"
}
}
native_social_login {
apple {
enabled = false
}
facebook {
enabled = true
}
}
}
`

const testAccClientConfigMobileUpdateNonMobile = `

resource "auth0_client" "my_client" {
name = "Acceptance Test - Mobile - {{.random}}"
app_type = "non_interactive"

native_social_login {
apple {
enabled = false
}
facebook {
enabled = false
}
}
}
`
Expand Down
21 changes: 21 additions & 0 deletions docs/resources/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Arguments accepted by this resource include:
* `token_endpoint_auth_method` - (Optional) String. Defines the requested authentication method for the token endpoint. Options include `none` (public client without a client secret), `client_secret_post` (client uses HTTP POST parameters), `client_secret_basic` (client uses HTTP Basic).
* `client_metadata` - (Optional) Map(String)
* `mobile` - (Optional) List(Resource). Configuration settings for mobile native applications. For details, see [Mobile](#mobile).
* `native_social_login` - (Optional) List(Resource). Configuration settings to toggle native social login for mobile native applications. For details, see [Native Social Login](#native-social-login)

### JWT Configuration

Expand Down Expand Up @@ -222,6 +223,26 @@ Arguments accepted by this resource include:
* `team_id` - (Optional) String
* `app_bundle_identifier` - (Optional) String

### Native Social Login

> Note: once this is set it must stay set, with both resources set to "false" in order to change the app_type

`native_social_login` supports the following arguments:

* `apple` (Optional) Resource:
* `facebook` (Optional) Resources:

#### Apple

`apple` supports the following arguments:

* `enabled` Boolean

#### Facebook

`facebook` supports the following arguments:

* `enabled` Boolean
## Attribute Reference

Attributes exported by this resource include:
Expand Down
1 change: 1 addition & 0 deletions scripts/gendocs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package main
Expand Down