Skip to content

Commit

Permalink
Add signing_keys to client resource
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Feb 23, 2022
1 parent 5ccc15c commit 6151377
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 53 deletions.
2 changes: 2 additions & 0 deletions auth0/data_source_auth0_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestAccDataClientByName(t *testing.T) {
Config: random.Template(fmt.Sprintf(testAccDataClientConfigByName, testAccClientConfig), rand),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.auth0_client.test", "client_id"),
resource.TestCheckResourceAttr("data.auth0_client.test", "signing_keys.#", "1"), // checks that signing_keys is set, and it includes 1 element
resource.TestCheckResourceAttr("data.auth0_client.test", "name", fmt.Sprintf("Acceptance Test - %v", rand)),
resource.TestCheckResourceAttr("data.auth0_client.test", "app_type", "non_interactive"), // Arbitrary property selection
resource.TestCheckNoResourceAttr("data.auth0_client.test", "client_secret_rotation_trigger"),
Expand Down Expand Up @@ -67,6 +68,7 @@ func TestAccDataClientById(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.auth0_client.test", "id"),
resource.TestCheckResourceAttrSet("data.auth0_client.test", "name"),
resource.TestCheckResourceAttr("data.auth0_client.test", "signing_keys.#", "1"), // checks that signing_keys is set, and it includes 1 element
resource.TestCheckNoResourceAttr("data.auth0_client.test", "client_secret_rotation_trigger"),
resource.TestCheckNoResourceAttr("data.auth0_client.test", "client_secret"),
),
Expand Down
14 changes: 1 addition & 13 deletions auth0/resource_auth0_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,20 +584,8 @@ func newClient() *schema.Resource {
},
"signing_keys": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeMap},
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cert": {
Type: schema.TypeString,
Computed: true,
},
"pkcs7": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
Expand Down
40 changes: 1 addition & 39 deletions auth0/resource_auth0_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func TestAccClient(t *testing.T) {
resource.TestCheckResourceAttr("auth0_client.my_client", "addons.0.samlp.0.signing_cert", "-----BEGIN PUBLIC KEY-----\nMIGf...bpP/t3\n+JGNGIRMj1hF1rnb6QIDAQAB\n-----END PUBLIC KEY-----\n"),
resource.TestCheckResourceAttr("auth0_client.my_client", "client_metadata.foo", "zoo"),
resource.TestCheckResourceAttr("auth0_client.my_client", "initiate_login_uri", "https://example.com/login"),
resource.TestCheckResourceAttr("auth0_client.my_client", "signing_keys.#", "1"), // checks that signing_keys is set, and it includes 1 element
),
},
},
Expand Down Expand Up @@ -483,42 +484,3 @@ resource "auth0_client" "my_client" {
}
}
`

func TestAccClientSigningKeys(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(testAccClientSigningKeysCreate, rand),
Check: resource.ComposeTestCheckFunc(
random.TestCheckResourceAttr("auth0_client.my_client", "name", "Acceptance Test - Signing Keys - {{.random}}", rand),
resource.TestCheckResourceAttrSet("auth0_client.my_client", "signing_keys.0.cert"),
),
},
{
Config: random.Template(testAccClientSigningKeysUpdate, rand),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("auth0_client.my_client", "signing_keys.0.cert"),
),
},
},
})
}

const testAccClientSigningKeysCreate = `
resource "auth0_client" "my_client" {
name = "Acceptance Test - Signing Keys - {{.random}}"
is_first_party = false
}
`

const testAccClientSigningKeysUpdate = `
resource "auth0_client" "my_client" {
name = "Acceptance Test - Signing Keys - {{.random}}"
is_first_party = true
}
`
3 changes: 2 additions & 1 deletion docs/resources/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ Attributes exported by this resource include:
* `grant_types` - List(String). Types of grants that this client is authorized to use.
* `custom_login_page_on` - Boolean. Indicates whether or not a custom login page is to be used.
* `token_endpoint_auth_method` - 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).
* `signing_keys` - List(Map). List containing a map of the public cert of the signing key and the public cert of the signing key in pkcs7
* `signing_keys` - List(Map). List containing a map of the public cert of the signing key and the public cert of the signing key in pkcs7.

### Client keys

To access the `client_secret` attribute you need to add the `read:client_keys` scope to the Terraform client. Otherwise, the attribute will contain an empty string.

0 comments on commit 6151377

Please sign in to comment.