Skip to content

Commit e9c2fd4

Browse files
author
Luc Dewavrin
committed
Have the provider set the smtp server authentication type to fix smtp authentication issues on realm updates in keycloak 26.2
1 parent 4b1348f commit e9c2fd4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

docs/resources/realm.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ resource "keycloak_realm" "realm" {
3333
3434
3535
auth {
36+
auth_type = "basic"
3637
username = "tom"
3738
password = "password"
39+
3840
}
3941
}
4042
@@ -161,6 +163,7 @@ This block supports the following arguments:
161163
- `auth` - (Optional) Enables authentication to the SMTP server. This block supports the following arguments:
162164
- `username` - (Required) The SMTP server username.
163165
- `password` - (Required) The SMTP server password.
166+
- auth_type - (Optional) The authentication type. Only `basic` is supported by the provider which is for password based authentication.
164167

165168
### Internationalization
166169

keycloak/realm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ type SmtpServer struct {
170170
Ssl types.KeycloakBoolQuoted `json:"ssl,omitempty"`
171171
User string `json:"user,omitempty"`
172172
Password string `json:"password,omitempty"`
173+
AuthType string `json:"authType,omitempty"`
173174
}
174175

175176
func (keycloakClient *KeycloakClient) NewRealm(ctx context.Context, realm *Realm) error {

provider/resource_keycloak_realm.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ func resourceKeycloakRealm() *schema.Resource {
303303
return smtpServerPassword == "**********"
304304
},
305305
},
306+
"auth_type": {
307+
Type: schema.TypeString,
308+
Optional: true,
309+
Default: "basic",
310+
ValidateFunc: validation.StringInSlice([]string{"basic"}, false), // Only basic is supported by the provider for now
311+
},
306312
},
307313
},
308314
},
@@ -815,6 +821,8 @@ func getRealmFromData(data *schema.ResourceData, keycloakVersion *version.Versio
815821
smtpServer.Auth = true
816822
smtpServer.User = auth["username"].(string)
817823
smtpServer.Password = auth["password"].(string)
824+
smtpServer.AuthType = auth["auth_type"].(string)
825+
818826
} else {
819827
smtpServer.Auth = false
820828
}
@@ -1245,6 +1253,7 @@ func setRealmData(data *schema.ResourceData, realm *keycloak.Realm, keycloakVers
12451253

12461254
auth["username"] = realm.SmtpServer.User
12471255
auth["password"] = realm.SmtpServer.Password
1256+
auth["auth_type"] = realm.SmtpServer.AuthType
12481257

12491258
smtpSettings["auth"] = []interface{}{auth}
12501259
}

0 commit comments

Comments
 (0)