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

Support admin_url attribute in openid clients #203

Merged
merged 5 commits into from Jan 27, 2020
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
3 changes: 2 additions & 1 deletion docs/resources/keycloak_openid_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ should be treated with the same care as a password. If omitted, Keycloak will ge
wildcards in the form of an asterisk can be used here. This attribute must be set if either `standard_flow_enabled` or `implicit_flow_enabled`
is set to `true`.
- `web_origins` - (Optional) A list of allowed CORS origins. `+` can be used to permit all valid redirect URIs, and `*` can be used to permit all origins.
- `admin_url` - (Optional) URL to the admin interface of the client.
- `base_url` - (Optional) Default URL to use when the auth server needs to redirect or link back to the client.
- `pkce_code_challenge_method` - (Optional) The challenge method to use for Proof Key for Code Exchange. Can be either `plain` or `S256` or set to empty value ``.
- `full_scope_allowed` - (Optional) - Allow to include all roles mappings in the access token.
Expand All @@ -62,7 +63,7 @@ is set to `true`.
In addition to the arguments listed above, the following computed attributes are exported:

- `service_account_user_id` - When service accounts are enabled for this client, this attribute is the unique ID for the Keycloak user that represents this service account.


### Import

Expand Down
1 change: 1 addition & 0 deletions keycloak/openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type OpenidClient struct {
AuthorizationServicesEnabled bool `json:"authorizationServicesEnabled"`
ValidRedirectUris []string `json:"redirectUris"`
WebOrigins []string `json:"webOrigins"`
AdminUrl string `json:"adminUrl"`
BaseUrl string `json:"baseUrl"`
FullScopeAllowed bool `json:"fullScopeAllowed"`
Attributes OpenidClientAttributes `json:"attributes"`
Expand Down
6 changes: 6 additions & 0 deletions provider/resource_keycloak_openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func resourceKeycloakOpenidClient() *schema.Resource {
Set: schema.HashString,
Optional: true,
},
"admin_url": {
Type: schema.TypeString,
Optional: true,
},
"base_url": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -181,6 +185,7 @@ func getOpenidClientFromData(data *schema.ResourceData) (*keycloak.OpenidClient,
},
ValidRedirectUris: validRedirectUris,
WebOrigins: webOrigins,
AdminUrl: data.Get("admin_url").(string),
BaseUrl: data.Get("base_url").(string),
}

Expand Down Expand Up @@ -240,6 +245,7 @@ func setOpenidClientData(keycloakClient *keycloak.KeycloakClient, data *schema.R
data.Set("service_accounts_enabled", client.ServiceAccountsEnabled)
data.Set("valid_redirect_uris", client.ValidRedirectUris)
data.Set("web_origins", client.WebOrigins)
data.Set("admin_url", client.AdminUrl)
data.Set("base_url", client.BaseUrl)
data.Set("authorization_services_enabled", client.AuthorizationServicesEnabled)
data.Set("full_scope_allowed", client.FullScopeAllowed)
Expand Down
51 changes: 50 additions & 1 deletion provider/resource_keycloak_openid_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ func TestAccKeycloakOpenidClient_accessType(t *testing.T) {
},
})
}
func TestAccKeycloakOpenidClient_adminUrl(t *testing.T) {
realmName := "terraform-" + acctest.RandString(10)
clientId := "terraform-" + acctest.RandString(10)
adminUrl := "https://www.example.com/admin"

resource.Test(t, resource.TestCase{
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
CheckDestroy: testAccCheckKeycloakOpenidClientDestroy(),
Steps: []resource.TestStep{
{
Config: testKeycloakOpenidClient_adminUrl(realmName, clientId, adminUrl),
Check: testAccCheckKeycloakOpenidClientAdminUrl("keycloak_openid_client.client", adminUrl),
},
},
})
}

func TestAccKeycloakOpenidClient_baseUrl(t *testing.T) {
realmName := "terraform-" + acctest.RandString(10)
Expand Down Expand Up @@ -165,6 +182,7 @@ func TestAccKeycloakOpenidClient_updateInPlace(t *testing.T) {
ServiceAccountsEnabled: serviceAccountsEnabled,
ValidRedirectUris: []string{acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10)},
WebOrigins: []string{acctest.RandString(10), acctest.RandString(10), acctest.RandString(10)},
AdminUrl: acctest.RandString(20),
BaseUrl: acctest.RandString(20),
}

Expand All @@ -183,6 +201,7 @@ func TestAccKeycloakOpenidClient_updateInPlace(t *testing.T) {
ServiceAccountsEnabled: !serviceAccountsEnabled,
ValidRedirectUris: []string{acctest.RandString(10), acctest.RandString(10)},
WebOrigins: []string{acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10)},
AdminUrl: acctest.RandString(20),
BaseUrl: acctest.RandString(20),
}

Expand Down Expand Up @@ -213,6 +232,21 @@ func TestAccKeycloakOpenidClient_updateInPlace(t *testing.T) {
})
}

func testAccCheckKeycloakOpenidClientAdminUrl(resourceName string, adminUrl string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client, err := getOpenidClientFromState(s, resourceName)
if err != nil {
return err
}

if client.AdminUrl != adminUrl {
return fmt.Errorf("expected openid client to have adminUrl set to %s, but got %s", adminUrl, client.AdminUrl)
}

return nil
}
}

func TestAccKeycloakOpenidClient_secret(t *testing.T) {
realmName := "terraform-" + acctest.RandString(10)
clientId := "terraform-" + acctest.RandString(10)
Expand Down Expand Up @@ -602,6 +636,20 @@ resource "keycloak_openid_client" "client" {
`, realm, clientId, accessType)
}

func testKeycloakOpenidClient_adminUrl(realm, clientId, adminUrl string) string {
return fmt.Sprintf(`
resource "keycloak_realm" "realm" {
realm = "%s"
}
resource "keycloak_openid_client" "client" {
client_id = "%s"
realm_id = "${keycloak_realm.realm.id}"
admin_url = "%s"
access_type = "PUBLIC"
}
`, realm, clientId, adminUrl)
}

func testKeycloakOpenidClient_baseUrl(realm, clientId, baseUrl string) string {
return fmt.Sprintf(`
resource "keycloak_realm" "realm" {
Expand Down Expand Up @@ -739,9 +787,10 @@ resource "keycloak_openid_client" "client" {

valid_redirect_uris = %s
web_origins = %s
admin_url = "%s"
base_url = "%s"
}
`, openidClient.RealmId, openidClient.ClientId, openidClient.Name, openidClient.Enabled, openidClient.Description, openidClient.ClientSecret, openidClient.StandardFlowEnabled, openidClient.ImplicitFlowEnabled, openidClient.DirectAccessGrantsEnabled, openidClient.ServiceAccountsEnabled, arrayOfStringsForTerraformResource(openidClient.ValidRedirectUris), arrayOfStringsForTerraformResource(openidClient.WebOrigins), openidClient.BaseUrl)
`, openidClient.RealmId, openidClient.ClientId, openidClient.Name, openidClient.Enabled, openidClient.Description, openidClient.ClientSecret, openidClient.StandardFlowEnabled, openidClient.ImplicitFlowEnabled, openidClient.DirectAccessGrantsEnabled, openidClient.ServiceAccountsEnabled, arrayOfStringsForTerraformResource(openidClient.ValidRedirectUris), arrayOfStringsForTerraformResource(openidClient.WebOrigins), openidClient.AdminUrl, openidClient.BaseUrl)
}

func testKeycloakOpenidClient_secret(realm, clientId, clientSecret string) string {
Expand Down