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

Commit 8ca0c0b

Browse files
authored
Merge pull request #453 from cthos/add-native-social
Implements the native_social_login stanza on the Client API.
2 parents 4ba15d3 + 553bba1 commit 8ca0c0b

File tree

5 files changed

+164
-1
lines changed

5 files changed

+164
-1
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.25.1
2+
3+
ENHANCEMENTS:
4+
5+
* resource/client: Add the `native_social_login` field for native `app_types` ([#453](https://github.com/alexkappa/terraform-provider-auth0/pull/453))
6+
7+
NOTES:
8+
9+
* Fix role docs [#398](https://github.com/alexkappa/terraform-provider-auth0/pull/398)
10+
111
## 0.25.0
212

313
ENHANCEMENTS:

auth0/resource_auth0_client.go

+76
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,42 @@ func newClient() *schema.Resource {
496496
v.IsURLWithNoFragment,
497497
),
498498
},
499+
"native_social_login": {
500+
Type: schema.TypeList,
501+
Optional: true,
502+
Computed: true,
503+
MaxItems: 1,
504+
Elem: &schema.Resource{
505+
Schema: map[string]*schema.Schema{
506+
"apple": {
507+
Type: schema.TypeList,
508+
Optional: true,
509+
MaxItems: 1,
510+
Elem: &schema.Resource{
511+
Schema: map[string]*schema.Schema{
512+
"enabled": {
513+
Type: schema.TypeBool,
514+
Optional: true,
515+
},
516+
},
517+
},
518+
},
519+
"facebook": {
520+
Type: schema.TypeList,
521+
Optional: true,
522+
MaxItems: 1,
523+
Elem: &schema.Resource{
524+
Schema: map[string]*schema.Schema{
525+
"enabled": {
526+
Type: schema.TypeBool,
527+
Optional: true,
528+
},
529+
},
530+
},
531+
},
532+
},
533+
},
534+
},
499535
"refresh_token": {
500536
Type: schema.TypeList,
501537
Optional: true,
@@ -595,6 +631,7 @@ func readClient(d *schema.ResourceData, m interface{}) error {
595631
d.Set("custom_login_page", c.CustomLoginPage)
596632
d.Set("form_template", c.FormTemplate)
597633
d.Set("token_endpoint_auth_method", c.TokenEndpointAuthMethod)
634+
d.Set("native_social_login", flattenCustomSocialConfiguration(c.NativeSocialLogin))
598635
d.Set("jwt_configuration", flattenClientJwtConfiguration(c.JWTConfiguration))
599636
d.Set("refresh_token", flattenClientRefreshTokenConfiguration(c.RefreshToken))
600637
d.Set("encryption_key", c.EncryptionKey)
@@ -747,6 +784,24 @@ func expandClient(d *schema.ResourceData) *management.Client {
747784
}
748785
}
749786

787+
List(d, "native_social_login").Elem(func(d ResourceData) {
788+
c.NativeSocialLogin = &management.ClientNativeSocialLogin{}
789+
790+
List(d, "apple").Elem(func(d ResourceData) {
791+
m := make(MapData)
792+
m.Set("enabled", Bool(d, "enabled"))
793+
794+
c.NativeSocialLogin.Apple = m
795+
})
796+
797+
List(d, "facebook").Elem(func(d ResourceData) {
798+
m := make(MapData)
799+
m.Set("enabled", Bool(d, "enabled"))
800+
801+
c.NativeSocialLogin.Facebook = m
802+
})
803+
})
804+
750805
List(d, "mobile").Elem(func(d ResourceData) {
751806

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

878+
func flattenCustomSocialConfiguration(customSocial *management.ClientNativeSocialLogin) []interface{} {
879+
if customSocial != nil {
880+
m := make(map[string]interface{})
881+
882+
if customSocial.Apple != nil {
883+
m["apple"] = map[string]interface{}{
884+
"enabled": customSocial.Apple["enabled"],
885+
}
886+
}
887+
if customSocial.Facebook != nil {
888+
m["facebook"] = map[string]interface{}{
889+
"enabled": customSocial.Facebook["enabled"],
890+
}
891+
}
892+
893+
return []interface{}{m}
894+
}
895+
896+
return nil
897+
}
898+
823899
func flattenClientJwtConfiguration(jwt *management.ClientJWTConfiguration) []interface{} {
824900
m := make(map[string]interface{})
825901
if jwt != nil {

auth0/resource_auth0_client_test.go

+56-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"strings"
77
"testing"
88

9-
"github.com/alexkappa/terraform-provider-auth0/auth0/internal/random"
109
"github.com/hashicorp/go-multierror"
1110
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1211
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1312

13+
"github.com/alexkappa/terraform-provider-auth0/auth0/internal/random"
14+
1415
"gopkg.in/auth0.v5/management"
1516
)
1617

@@ -379,6 +380,8 @@ func TestAccClientMobile(t *testing.T) {
379380
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.app_package_name", "com.example"),
380381
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.sha256_cert_fingerprints.#", "1"),
381382
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.sha256_cert_fingerprints.0", "DE:AD:BE:EF"),
383+
resource.TestCheckResourceAttr("auth0_client.my_client", "native_social_login.0.apple.0.enabled", "true"),
384+
resource.TestCheckResourceAttr("auth0_client.my_client", "native_social_login.0.facebook.0.enabled", "false"),
382385
),
383386
},
384387
{
@@ -387,6 +390,15 @@ func TestAccClientMobile(t *testing.T) {
387390
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.#", "1"),
388391
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.app_package_name", "com.example"),
389392
resource.TestCheckResourceAttr("auth0_client.my_client", "mobile.0.android.0.sha256_cert_fingerprints.#", "0"),
393+
resource.TestCheckResourceAttr("auth0_client.my_client", "native_social_login.0.apple.0.enabled", "false"),
394+
resource.TestCheckResourceAttr("auth0_client.my_client", "native_social_login.0.facebook.0.enabled", "true"),
395+
),
396+
},
397+
{
398+
// This just makes sure that you can change the type (where native_social_login cannot be set)
399+
Config: random.Template(testAccClientConfigMobileUpdateNonMobile, rand),
400+
Check: resource.ComposeTestCheckFunc(
401+
resource.TestCheckResourceAttr("auth0_client.my_client", "app_type", "non_interactive"),
390402
),
391403
},
392404
},
@@ -397,11 +409,24 @@ const testAccClientConfigMobile = `
397409
398410
resource "auth0_client" "my_client" {
399411
name = "Acceptance Test - Mobile - {{.random}}"
412+
app_type = "native"
400413
mobile {
401414
android {
402415
app_package_name = "com.example"
403416
sha256_cert_fingerprints = ["DE:AD:BE:EF"]
404417
}
418+
ios {
419+
team_id = "9JA89QQLNQ"
420+
app_bundle_identifier = "com.my.bundle.id"
421+
}
422+
}
423+
native_social_login {
424+
apple {
425+
enabled = true
426+
}
427+
facebook {
428+
enabled = false
429+
}
405430
}
406431
}
407432
`
@@ -410,11 +435,41 @@ const testAccClientConfigMobileUpdate = `
410435
411436
resource "auth0_client" "my_client" {
412437
name = "Acceptance Test - Mobile - {{.random}}"
438+
app_type = "native"
413439
mobile {
414440
android {
415441
app_package_name = "com.example"
416442
sha256_cert_fingerprints = []
417443
}
444+
ios {
445+
team_id = "1111111111"
446+
app_bundle_identifier = "com.my.auth0.bundle"
447+
}
448+
}
449+
native_social_login {
450+
apple {
451+
enabled = false
452+
}
453+
facebook {
454+
enabled = true
455+
}
456+
}
457+
}
458+
`
459+
460+
const testAccClientConfigMobileUpdateNonMobile = `
461+
462+
resource "auth0_client" "my_client" {
463+
name = "Acceptance Test - Mobile - {{.random}}"
464+
app_type = "non_interactive"
465+
466+
native_social_login {
467+
apple {
468+
enabled = false
469+
}
470+
facebook {
471+
enabled = false
472+
}
418473
}
419474
}
420475
`

docs/resources/client.md

+21
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Arguments accepted by this resource include:
115115
* `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).
116116
* `client_metadata` - (Optional) Map(String)
117117
* `mobile` - (Optional) List(Resource). Configuration settings for mobile native applications. For details, see [Mobile](#mobile).
118+
* `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)
118119

119120
### JWT Configuration
120121

@@ -222,6 +223,26 @@ Arguments accepted by this resource include:
222223
* `team_id` - (Optional) String
223224
* `app_bundle_identifier` - (Optional) String
224225

226+
### Native Social Login
227+
228+
> Note: once this is set it must stay set, with both resources set to "false" in order to change the app_type
229+
230+
`native_social_login` supports the following arguments:
231+
232+
* `apple` (Optional) Resource:
233+
* `facebook` (Optional) Resources:
234+
235+
#### Apple
236+
237+
`apple` supports the following arguments:
238+
239+
* `enabled` Boolean
240+
241+
#### Facebook
242+
243+
`facebook` supports the following arguments:
244+
245+
* `enabled` Boolean
225246
## Attribute Reference
226247

227248
Attributes exported by this resource include:

scripts/gendocs.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build ignore
12
// +build ignore
23

34
package main

0 commit comments

Comments
 (0)