Skip to content

Commit

Permalink
feat: Add option to configure always_display_in_console for saml and …
Browse files Browse the repository at this point in the history
…oidc clients

Signed-off-by: Michael Chittka <[email protected]>
  • Loading branch information
mchittka committed Feb 4, 2025
1 parent 2a6926d commit fb0d680
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ terraform-provider-keycloak_*
*.out

.idea/
.vscode/
.terraform/
terraform.d/
.terraform.lock.hcl
Expand Down
1 change: 1 addition & 0 deletions docs/resources/openid_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ is set to `true`.
- `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.
- `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`.
- `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.
- `always_display_in_console` - (Optional) Always list this client in the Account UI, even if the user does not have an active session.
- `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
``` hcl
extra_config = {
Expand Down
1 change: 1 addition & 0 deletions docs/resources/saml_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ resource "keycloak_saml_client" "saml_client" {
- `authentication_flow_binding_overrides` - (Optional) Override realm authentication flow bindings
- `browser_id` - (Optional) Browser flow id, (flow needs to exist)
- `direct_grant_id` - (Optional) Direct grant flow id (flow needs to exist)
- `always_display_in_console` - (Optional) Always list this client in the Account UI, even if the user does not have an active session.
- `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.

## Attributes Reference
Expand Down
1 change: 1 addition & 0 deletions keycloak/generic_client_description_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type GenericClientRepresentation struct {
StandardFlowEnabled bool `json:"standardFlowEnabled"`
SurrogateAuthRequired bool `json:"surrogateAuthRequired"`
WebOrigins []string `json:"webOrigins"`
AlwaysDisplayInConsole bool `json:"alwaysDisplayInConsole"`
}

func (keycloakClient *KeycloakClient) NewGenericClientDescription(ctx context.Context, realmId string, body string) (*GenericClientRepresentation, error) {
Expand Down
4 changes: 3 additions & 1 deletion keycloak/openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package keycloak
import (
"context"
"fmt"
"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
"reflect"

"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
)

type OpenidClientRole struct {
Expand Down Expand Up @@ -56,6 +57,7 @@ type OpenidClient struct {
AuthorizationSettings *OpenidClientAuthorizationSettings `json:"authorizationSettings,omitempty"`
ConsentRequired bool `json:"consentRequired"`
AuthenticationFlowBindingOverrides OpenidAuthenticationFlowBindingOverrides `json:"authenticationFlowBindingOverrides,omitempty"`
AlwaysDisplayInConsole bool `json:"alwaysDisplayInConsole"`
}

type OpenidClientAttributes struct {
Expand Down
5 changes: 4 additions & 1 deletion keycloak/saml_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package keycloak
import (
"context"
"fmt"
"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
"reflect"

"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
)

type SamlClientAttributes struct {
Expand Down Expand Up @@ -58,6 +59,8 @@ type SamlClient struct {

FullScopeAllowed bool `json:"fullScopeAllowed"`

AlwaysDisplayInConsole bool `json:"alwaysDisplayInConsole"`

Attributes *SamlClientAttributes `json:"attributes"`

AuthenticationFlowBindingOverrides SamlAuthenticationFlowBindingOverrides `json:"authenticationFlowBindingOverrides,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions provider/data_source_keycloak_client_description_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/keycloak/terraform-provider-keycloak/keycloak"
Expand Down Expand Up @@ -189,6 +190,10 @@ func dataSourceKeycloakClientDescriptionConverter() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"always_display_in_console": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -231,6 +236,7 @@ func setClientDescriptionConverterData(data *schema.ResourceData, description *k
data.Set("standard_flow_enabled", description.StandardFlowEnabled)
data.Set("surrogate_auth_required", description.SurrogateAuthRequired)
data.Set("web_origins", description.WebOrigins)
data.Set("always_display_in_console", description.AlwaysDisplayInConsole)
}

func dataSourceKeycloakClientDescriptionConverterRead(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down
5 changes: 5 additions & 0 deletions provider/data_source_keycloak_openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func dataSourceKeycloakOpenidClient() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"always_display_in_console": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down
5 changes: 5 additions & 0 deletions provider/data_source_keycloak_saml_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/keycloak/terraform-provider-keycloak/keycloak"
Expand Down Expand Up @@ -178,6 +179,10 @@ func dataSourceKeycloakSamlClient() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"always_display_in_console": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand Down
17 changes: 12 additions & 5 deletions provider/resource_keycloak_openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ func resourceKeycloakOpenidClient() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"always_display_in_console": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"import": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -376,11 +381,12 @@ func getOpenidClientFromData(data *schema.ResourceData) (*keycloak.OpenidClient,
DisplayOnConsentScreen: types.KeycloakBoolQuoted(data.Get("display_on_consent_screen").(bool)),
PostLogoutRedirectUris: types.KeycloakSliceHashDelimited(validPostLogoutRedirectUris),
},
ValidRedirectUris: validRedirectUris,
WebOrigins: webOrigins,
AdminUrl: data.Get("admin_url").(string),
BaseUrl: data.Get("base_url").(string),
ConsentRequired: data.Get("consent_required").(bool),
ValidRedirectUris: validRedirectUris,
WebOrigins: webOrigins,
AdminUrl: data.Get("admin_url").(string),
BaseUrl: data.Get("base_url").(string),
ConsentRequired: data.Get("consent_required").(bool),
AlwaysDisplayInConsole: data.Get("always_display_in_console").(bool),
}

if rootUrlOk {
Expand Down Expand Up @@ -462,6 +468,7 @@ func setOpenidClientData(ctx context.Context, keycloakClient *keycloak.KeycloakC
data.Set("root_url", &client.RootUrl)
data.Set("full_scope_allowed", client.FullScopeAllowed)
data.Set("consent_required", client.ConsentRequired)
data.Set("always_display_in_console", client.AlwaysDisplayInConsole)

data.Set("access_token_lifespan", client.Attributes.AccessTokenLifespan)
data.Set("login_theme", client.Attributes.LoginTheme)
Expand Down
12 changes: 10 additions & 2 deletions provider/resource_keycloak_saml_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"encoding/hex"
"errors"
"fmt"
"reflect"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/keycloak/terraform-provider-keycloak/keycloak/types"
"reflect"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -235,6 +236,11 @@ func resourceKeycloakSamlClient() *schema.Resource {
Optional: true,
ValidateDiagFunc: validateExtraConfig(reflect.ValueOf(&keycloak.SamlClientAttributes{}).Elem()),
},
"always_display_in_console": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down Expand Up @@ -315,6 +321,7 @@ func mapToSamlClientFromData(data *schema.ResourceData) *keycloak.SamlClient {
BaseUrl: data.Get("base_url").(string),
MasterSamlProcessingUrl: data.Get("master_saml_processing_url").(string),
FullScopeAllowed: data.Get("full_scope_allowed").(bool),
AlwaysDisplayInConsole: data.Get("always_display_in_console").(bool),
Attributes: samlAttributes,
}

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

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

0 comments on commit fb0d680

Please sign in to comment.