Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom_headers option to OAuth2 social connections #917

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/data-sources/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Read-Only:
- `community_base_url` (String)
- `configuration` (Map of String)
- `connection_settings` (List of Object) (see [below for nested schema](#nestedobjatt--options--connection_settings))
- `custom_headers` (List of Map of String)
- `custom_scripts` (Map of String)
- `debug` (Boolean)
- `decryption_key` (List of Object) (see [below for nested schema](#nestedobjatt--options--decryption_key))
Expand Down
1 change: 1 addition & 0 deletions docs/resources/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ Optional:
- `community_base_url` (String) Salesforce community base URL.
- `configuration` (Map of String, Sensitive) A case-sensitive map of key value pairs used as configuration variables for the `custom_script`.
- `connection_settings` (Block List, Max: 1) Proof Key for Code Exchange (PKCE) configuration settings for an OIDC or Okta Workforce connection. (see [below for nested schema](#nestedblock--options--connection_settings))
- `custom_headers` (List of Map of String) Configure extra headers to the Token endpoint of an OAuth 2.0 provider
- `custom_scripts` (Map of String) A map of scripts used to integrate with a custom database.
- `debug` (Boolean) When enabled, additional debug information will be generated.
- `decryption_key` (Block List, Max: 1) The key used to decrypt encrypted responses from the connection. Uses the `key` and `cert` properties to provide the private key and certificate respectively. (see [below for nested schema](#nestedblock--options--decryption_key))
Expand Down
13 changes: 13 additions & 0 deletions internal/auth0/connection/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,19 @@
Scripts: value.MapOfStrings(config.GetAttr("scripts")),
}

customHeadersConfig := config.GetAttr("custom_headers")

if !customHeadersConfig.IsNull() {
customHeaders := make([]map[string]string, 0)

customHeadersConfig.ForEachElement(func(_ cty.Value, httpHeader cty.Value) (stop bool) {
customHeaders = append(customHeaders, *value.MapOfStrings(httpHeader))
return stop
})

options.CustomHeaders = &customHeaders

Check failure on line 386 in internal/auth0/connection/expand.go

View workflow job for this annotation

GitHub Actions / Vulnerabilities Scan

options.CustomHeaders undefined (type *management.ConnectionOptionsOAuth2 has no field or method CustomHeaders)

Check failure on line 386 in internal/auth0/connection/expand.go

View workflow job for this annotation

GitHub Actions / Checks

options.CustomHeaders undefined (type *management.ConnectionOptionsOAuth2 has no field or method CustomHeaders)

Check failure on line 386 in internal/auth0/connection/expand.go

View workflow job for this annotation

GitHub Actions / Tests

options.CustomHeaders undefined (type *management.ConnectionOptionsOAuth2 has no field or method CustomHeaders)

Check failure on line 386 in internal/auth0/connection/expand.go

View workflow job for this annotation

GitHub Actions / Tests

options.CustomHeaders undefined (type *management.ConnectionOptionsOAuth2 has no field or method CustomHeaders)
}

expandConnectionOptionsScopes(data, options)

var err error
Expand Down
1 change: 1 addition & 0 deletions internal/auth0/connection/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
"icon_url": options.GetLogoURL(),
"pkce_enabled": options.GetPKCEEnabled(),
"upstream_params": upstreamParams,
"custom_headers": options.CustomHeaders,

Check failure on line 330 in internal/auth0/connection/flatten.go

View workflow job for this annotation

GitHub Actions / Vulnerabilities Scan

options.CustomHeaders undefined (type *management.ConnectionOptionsOAuth2 has no field or method CustomHeaders)

Check failure on line 330 in internal/auth0/connection/flatten.go

View workflow job for this annotation

GitHub Actions / Checks

options.CustomHeaders undefined (type *management.ConnectionOptionsOAuth2 has no field or method CustomHeaders)

Check failure on line 330 in internal/auth0/connection/flatten.go

View workflow job for this annotation

GitHub Actions / Tests

options.CustomHeaders undefined (type *management.ConnectionOptionsOAuth2 has no field or method CustomHeaders)

Check failure on line 330 in internal/auth0/connection/flatten.go

View workflow job for this annotation

GitHub Actions / Tests

options.CustomHeaders undefined (type *management.ConnectionOptionsOAuth2 has no field or method CustomHeaders)
}

return optionsMap, nil
Expand Down
17 changes: 17 additions & 0 deletions internal/auth0/connection/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ func TestAccConnectionOAuth2(t *testing.T) {
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.icon_url", ""),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.pkce_enabled", "true"),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.upstream_params", "{\"screen_name\":{\"alias\":\"login_hint\"}}"),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.custom_headers.#", "0"),
),
},
{
Expand All @@ -947,6 +948,11 @@ func TestAccConnectionOAuth2(t *testing.T) {
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.icon_url", "https://cdn.paypal.com/assets/logo.png"),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.pkce_enabled", "false"),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.upstream_params", ""),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.custom_headers.#", "2"),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.custom_headers.0.header", "foo"),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.custom_headers.0.value", "bar"),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.custom_headers.1.header", "bar"),
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.custom_headers.1.value", "foo"),
),
},
},
Expand Down Expand Up @@ -974,6 +980,7 @@ resource "auth0_connection" "oauth2" {
"alias": "login_hint"
}
})
custom_headers = []
}
}
`
Expand All @@ -995,6 +1002,16 @@ resource "auth0_connection" "oauth2" {
fetchUserProfile= "function( { return callback(null) }"
}
pkce_enabled = false
custom_headers = [
{
header = "foo"
value = "bar"
},
{
header = "bar"
value = "foo"
}
]
}
}
`
Expand Down
12 changes: 12 additions & 0 deletions internal/auth0/connection/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ var optionsSchema = &schema.Schema{
Sensitive: true,
Description: "The strategy's client secret.",
},
"custom_headers": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
Optional: true,
Default: nil,
Description: "Configure extra headers to the Token endpoint of an OAuth 2.0 provider",
},
"allowed_audiences": {
Type: schema.TypeSet,
Computed: true,
Expand Down
Loading