Skip to content

Commit 9411368

Browse files
authored
feat: Add option to configure always_display_in_console for saml and oidc clients (#1114)
Signed-off-by: Michael Chittka <[email protected]>
1 parent 9ee4f2d commit 9411368

11 files changed

+49
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ terraform-provider-keycloak_*
1414
*.out
1515

1616
.idea/
17+
.vscode/
1718
.terraform/
1819
terraform.d/
1920
.terraform.lock.hcl

docs/resources/openid_client.md

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ is set to `true`.
101101
- `backchannel_logout_url` - (Optional) The URL that will cause the client to log itself out when a logout request is sent to this realm. If omitted, no logout request will be sent to the client is this case.
102102
- `backchannel_logout_session_required` - (Optional) When `true`, a sid (session ID) claim will be included in the logout token when the backchannel logout URL is used. Defaults to `true`.
103103
- `backchannel_logout_revoke_offline_sessions` - (Optional) Specifying whether a "revoke_offline_access" event is included in the Logout Token when the Backchannel Logout URL is used. Keycloak will revoke offline sessions when receiving a Logout Token with this event.
104+
- `always_display_in_console` - (Optional) Always list this client in the Account UI, even if the user does not have an active session.
104105
- `extra_config` - (Optional) A map of key/value pairs to add extra configuration attributes to this client. This can be used for custom attributes, or to add configuration attributes that are not yet supported by this Terraform provider. Use this attribute at your own risk, as it may conflict with top-level configuration attributes in future provider updates. For example, the `extra_config` map can be used to set Authentication Context Class Reference (ACR) to Level of Authentication (LoA) mapping
105106
``` hcl
106107
extra_config = {

docs/resources/saml_client.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ resource "keycloak_saml_client" "saml_client" {
6868
- `authentication_flow_binding_overrides` - (Optional) Override realm authentication flow bindings
6969
- `browser_id` - (Optional) Browser flow id, (flow needs to exist)
7070
- `direct_grant_id` - (Optional) Direct grant flow id (flow needs to exist)
71+
- `always_display_in_console` - (Optional) Always list this client in the Account UI, even if the user does not have an active session.
7172
- `extra_config` - (Optional) A map of key/value pairs to add extra configuration attributes to this client. This can be used for custom attributes, or to add configuration attributes that is not yet supported by this Terraform provider. Use this attribute at your own risk, as s may conflict with top-level configuration attributes in future provider updates.
7273

7374
## Attributes Reference

keycloak/generic_client_description_converter.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type GenericClientRepresentation struct {
4444
StandardFlowEnabled bool `json:"standardFlowEnabled"`
4545
SurrogateAuthRequired bool `json:"surrogateAuthRequired"`
4646
WebOrigins []string `json:"webOrigins"`
47+
AlwaysDisplayInConsole bool `json:"alwaysDisplayInConsole"`
4748
}
4849

4950
func (keycloakClient *KeycloakClient) NewGenericClientDescription(ctx context.Context, realmId string, body string) (*GenericClientRepresentation, error) {

keycloak/openid_client.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package keycloak
33
import (
44
"context"
55
"fmt"
6-
"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
76
"reflect"
7+
8+
"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
89
)
910

1011
type OpenidClientRole struct {
@@ -56,6 +57,7 @@ type OpenidClient struct {
5657
AuthorizationSettings *OpenidClientAuthorizationSettings `json:"authorizationSettings,omitempty"`
5758
ConsentRequired bool `json:"consentRequired"`
5859
AuthenticationFlowBindingOverrides OpenidAuthenticationFlowBindingOverrides `json:"authenticationFlowBindingOverrides,omitempty"`
60+
AlwaysDisplayInConsole bool `json:"alwaysDisplayInConsole"`
5961
}
6062

6163
type OpenidClientAttributes struct {

keycloak/saml_client.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package keycloak
33
import (
44
"context"
55
"fmt"
6-
"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
76
"reflect"
7+
8+
"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
89
)
910

1011
type SamlClientAttributes struct {
@@ -58,6 +59,8 @@ type SamlClient struct {
5859

5960
FullScopeAllowed bool `json:"fullScopeAllowed"`
6061

62+
AlwaysDisplayInConsole bool `json:"alwaysDisplayInConsole"`
63+
6164
Attributes *SamlClientAttributes `json:"attributes"`
6265

6366
AuthenticationFlowBindingOverrides SamlAuthenticationFlowBindingOverrides `json:"authenticationFlowBindingOverrides,omitempty"`

provider/data_source_keycloak_client_description_converter.go

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
56
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
78
"github.com/keycloak/terraform-provider-keycloak/keycloak"
@@ -189,6 +190,10 @@ func dataSourceKeycloakClientDescriptionConverter() *schema.Resource {
189190
Elem: &schema.Schema{Type: schema.TypeString},
190191
Computed: true,
191192
},
193+
"always_display_in_console": {
194+
Type: schema.TypeBool,
195+
Computed: true,
196+
},
192197
},
193198
}
194199
}
@@ -231,6 +236,7 @@ func setClientDescriptionConverterData(data *schema.ResourceData, description *k
231236
data.Set("standard_flow_enabled", description.StandardFlowEnabled)
232237
data.Set("surrogate_auth_required", description.SurrogateAuthRequired)
233238
data.Set("web_origins", description.WebOrigins)
239+
data.Set("always_display_in_console", description.AlwaysDisplayInConsole)
234240
}
235241

236242
func dataSourceKeycloakClientDescriptionConverterRead(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {

provider/data_source_keycloak_openid_client.go

+5
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ func dataSourceKeycloakOpenidClient() *schema.Resource {
238238
Type: schema.TypeString,
239239
Optional: true,
240240
},
241+
"always_display_in_console": {
242+
Type: schema.TypeBool,
243+
Optional: true,
244+
Default: false,
245+
},
241246
},
242247
}
243248
}

provider/data_source_keycloak_saml_client.go

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
56
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
78
"github.com/keycloak/terraform-provider-keycloak/keycloak"
@@ -178,6 +179,10 @@ func dataSourceKeycloakSamlClient() *schema.Resource {
178179
Type: schema.TypeString,
179180
Computed: true,
180181
},
182+
"always_display_in_console": {
183+
Type: schema.TypeBool,
184+
Computed: true,
185+
},
181186
},
182187
}
183188
}

provider/resource_keycloak_openid_client.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ func resourceKeycloakOpenidClient() *schema.Resource {
300300
Type: schema.TypeString,
301301
Optional: true,
302302
},
303+
"always_display_in_console": {
304+
Type: schema.TypeBool,
305+
Optional: true,
306+
Default: false,
307+
},
303308
"import": {
304309
Type: schema.TypeBool,
305310
Optional: true,
@@ -382,11 +387,12 @@ func getOpenidClientFromData(data *schema.ResourceData) (*keycloak.OpenidClient,
382387
DisplayOnConsentScreen: types.KeycloakBoolQuoted(data.Get("display_on_consent_screen").(bool)),
383388
PostLogoutRedirectUris: types.KeycloakSliceHashDelimited(validPostLogoutRedirectUris),
384389
},
385-
ValidRedirectUris: validRedirectUris,
386-
WebOrigins: webOrigins,
387-
AdminUrl: data.Get("admin_url").(string),
388-
BaseUrl: data.Get("base_url").(string),
389-
ConsentRequired: data.Get("consent_required").(bool),
390+
ValidRedirectUris: validRedirectUris,
391+
WebOrigins: webOrigins,
392+
AdminUrl: data.Get("admin_url").(string),
393+
BaseUrl: data.Get("base_url").(string),
394+
ConsentRequired: data.Get("consent_required").(bool),
395+
AlwaysDisplayInConsole: data.Get("always_display_in_console").(bool),
390396
}
391397

392398
if rootUrlOk {
@@ -468,6 +474,7 @@ func setOpenidClientData(ctx context.Context, keycloakClient *keycloak.KeycloakC
468474
data.Set("root_url", &client.RootUrl)
469475
data.Set("full_scope_allowed", client.FullScopeAllowed)
470476
data.Set("consent_required", client.ConsentRequired)
477+
data.Set("always_display_in_console", client.AlwaysDisplayInConsole)
471478

472479
data.Set("access_token_lifespan", client.Attributes.AccessTokenLifespan)
473480
data.Set("login_theme", client.Attributes.LoginTheme)

provider/resource_keycloak_saml_client.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"encoding/hex"
88
"errors"
99
"fmt"
10+
"reflect"
11+
"strings"
12+
1013
"github.com/hashicorp/terraform-plugin-log/tflog"
1114
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1215
"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
13-
"reflect"
14-
"strings"
1516

1617
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1718
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
@@ -235,6 +236,11 @@ func resourceKeycloakSamlClient() *schema.Resource {
235236
Optional: true,
236237
ValidateDiagFunc: validateExtraConfig(reflect.ValueOf(&keycloak.SamlClientAttributes{}).Elem()),
237238
},
239+
"always_display_in_console": {
240+
Type: schema.TypeBool,
241+
Optional: true,
242+
Default: false,
243+
},
238244
},
239245
}
240246
}
@@ -315,6 +321,7 @@ func mapToSamlClientFromData(data *schema.ResourceData) *keycloak.SamlClient {
315321
BaseUrl: data.Get("base_url").(string),
316322
MasterSamlProcessingUrl: data.Get("master_saml_processing_url").(string),
317323
FullScopeAllowed: data.Get("full_scope_allowed").(bool),
324+
AlwaysDisplayInConsole: data.Get("always_display_in_console").(bool),
318325
Attributes: samlAttributes,
319326
}
320327

@@ -371,6 +378,7 @@ func mapToDataFromSamlClient(ctx context.Context, data *schema.ResourceData, cli
371378
data.Set("logout_service_redirect_binding_url", client.Attributes.LogoutServiceRedirectBindingURL)
372379
data.Set("full_scope_allowed", client.FullScopeAllowed)
373380
data.Set("login_theme", client.Attributes.LoginTheme)
381+
data.Set("always_display_in_console", client.AlwaysDisplayInConsole)
374382

375383
if canonicalizationMethod, ok := mapKeyFromValue(keycloakSamlClientCanonicalizationMethods, client.Attributes.CanonicalizationMethod); ok {
376384
data.Set("canonicalization_method", canonicalizationMethod)

0 commit comments

Comments
 (0)