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

Commit

Permalink
Merge pull request #221 from relu/facebook-connection-provider-support
Browse files Browse the repository at this point in the history
Support for Facebook connection provider config
  • Loading branch information
alexkappa authored May 7, 2020
2 parents 1884098 + a0baf6f commit 95b8035
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
65 changes: 65 additions & 0 deletions auth0/resource_auth0_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,71 @@ resource "auth0_connection" "google_oauth2" {
}
`

func TestAccConnectionFacebook(t *testing.T) {

rand := random.String(6)

resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
"auth0": Provider(),
},
Steps: []resource.TestStep{
{
Config: random.Template(testAccConnectionFacebookConfig, rand),
Check: resource.ComposeTestCheckFunc(
random.TestCheckResourceAttr("auth0_connection.facebook", "name", "Acceptance-Test-Facebook-{{.random}}", rand),
resource.TestCheckResourceAttr("auth0_connection.facebook", "strategy", "facebook"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.client_id", "client_id"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.client_secret", "client_secret"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.scopes.#", "4"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.scopes.3590537325", "public_profile"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.scopes.881205744", "email"),
),
},
{
Config: random.Template(testAccConnectionFacebookConfigUpdate, rand),
Check: resource.ComposeTestCheckFunc(
random.TestCheckResourceAttr("auth0_connection.facebook", "name", "Acceptance-Test-Facebook-{{.random}}", rand),
resource.TestCheckResourceAttr("auth0_connection.facebook", "strategy", "facebook"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.client_id", "client_id_update"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.client_secret", "client_secret_update"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.scopes.#", "2"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.scopes.3590537325", "public_profile"),
resource.TestCheckResourceAttr("auth0_connection.facebook", "options.0.scopes.881205744", "email"),
),
},
},
})
}

const testAccConnectionFacebookConfig = `
resource "auth0_connection" "facebook" {
name = "Acceptance-Test-Facebook-{{.random}}"
is_domain_connection = false
strategy = "facebook"
options {
client_id = "client_id"
client_secret = "client_secret"
scopes = [ "public_profile", "email", "groups_access_member_info", "user_birthday" ]
}
}
`

const testAccConnectionFacebookConfigUpdate = `
resource "auth0_connection" "facebook" {
name = "Acceptance-Test-Facebook-{{.random}}"
is_domain_connection = false
strategy = "facebook"
options {
client_id = "client_id_update"
client_secret = "client_secret_update"
scopes = [ "public_profile", "email" ]
}
}
`

func TestAccConnectionApple(t *testing.T) {

rand := random.String(6)
Expand Down
27 changes: 24 additions & 3 deletions auth0/structure_auth0_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func flattenConnectionOptions(d Data, options interface{}) []interface{} {
m = flattenConnectionOptionsAuth0(d, o)
case *management.ConnectionOptionsGoogleOAuth2:
m = flattenConnectionOptionsGoogleOAuth2(o)
// case *management.ConnectionOptionsFacebook:
// m = flattenConnectionOptionsFacebook(o)
case *management.ConnectionOptionsFacebook:
m = flattenConnectionOptionsFacebook(o)
case *management.ConnectionOptionsApple:
m = flattenConnectionOptionsApple(o)
// case *management.ConnectionOptionsLinkedin:
Expand Down Expand Up @@ -79,6 +79,14 @@ func flattenConnectionOptionsGoogleOAuth2(o *management.ConnectionOptionsGoogleO
}
}

func flattenConnectionOptionsFacebook(o *management.ConnectionOptionsFacebook) interface{} {
return map[string]interface{}{
"client_id": o.GetClientID(),
"client_secret": o.GetClientSecret(),
"scopes": o.Scopes(),
}
}

func flattenConnectionOptionsApple(o *management.ConnectionOptionsApple) interface{} {
return map[string]interface{}{
"client_id": o.GetClientID(),
Expand Down Expand Up @@ -182,9 +190,10 @@ func expandConnection(d Data) *management.Connection {
c.Options = expandConnectionOptionsAuth0(d)
case management.ConnectionStrategyGoogleOAuth2:
c.Options = expandConnectionOptionsGoogleOAuth2(d)
case management.ConnectionStrategyFacebook:
c.Options = expandConnectionOptionsFacebook(d)
case management.ConnectionStrategyApple:
c.Options = expandConnectionOptionsApple(d)
// case management.ConnectionStrategyFacebook
// management.ConnectionStrategyLinkedin
case management.ConnectionStrategyGitHub:
c.Options = expandConnectionOptionsGitHub(d)
Expand Down Expand Up @@ -277,6 +286,18 @@ func expandConnectionOptionsGoogleOAuth2(d Data) *management.ConnectionOptionsGo
return o
}

func expandConnectionOptionsFacebook(d Data) *management.ConnectionOptionsFacebook {

o := &management.ConnectionOptionsFacebook{
ClientID: String(d, "client_id"),
ClientSecret: String(d, "client_secret"),
}

expandConnectionOptionsScopes(d, o)

return o
}

func expandConnectionOptionsApple(d Data) *management.ConnectionOptionsApple {

o := &management.ConnectionOptionsApple{
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/connection.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ Arguments accepted by this resource include:
* `custom_scripts` - (Optional) Map(String).
* `configuration` - (Optional) Map(String), Case-sensitive.

**Facebook**

* `client_id` - (Optional) String. Corresponds to the Facebook application ID.
* `client_secret` - (Optional) String, Case-sensitive. The Facebook application client secret.

**Azure AD Options**

* `app_id` - (Optional) String
Expand Down

0 comments on commit 95b8035

Please sign in to comment.