Skip to content

Commit df873ed

Browse files
authored
[CLOUDTRUST-7719] Add IDNow configuration in context key (#706)
1 parent 03a28c0 commit df873ed

5 files changed

Lines changed: 70 additions & 4 deletions

File tree

api/management/api.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ type CtxKeyConfigRepresentation struct {
408408
Onboarding CtxKeyOnboardingRepresentation `json:"onboarding"`
409409
Accreditation CtxKeyAccreditationRepresentation `json:"accreditation"`
410410
AutoVoucher CtxKeyAutoVoucherRepresentation `json:"autovoucher"`
411+
IDNow CtxKeyIDNowRepresentation `json:"idnow"`
411412
}
412413

413414
// CtxKeyOnboardingRepresentation struct
@@ -430,6 +431,11 @@ type CtxKeyAutoVoucherRepresentation struct {
430431
BilledRealm *string `json:"billedRealm"`
431432
}
432433

434+
// CtxKeyIDNowRepresentation struct
435+
type CtxKeyIDNowRepresentation struct {
436+
DesktopRedirectURI *string `json:"desktopRedirectUri"`
437+
}
438+
433439
// RequiredAction type
434440
type RequiredAction string
435441

@@ -1472,6 +1478,7 @@ func ConvertToAPIContextKeyConfig(config configuration.ContextKeyConfiguration)
14721478
Onboarding: ConvertToAPIContextKeyOnboarding(config.Onboarding),
14731479
Accreditation: ConvertToAPIContextKeyAccreditation(config.Accreditation),
14741480
AutoVoucher: ConvertToAPIContextKeyAutovoucher(config.AutoVoucher),
1481+
IDNow: ConvertToAPIContextKeyIDNow(config.IDNow),
14751482
}
14761483
}
14771484

@@ -1480,12 +1487,14 @@ func (c *CtxKeyConfigRepresentation) ToDatabaseModel() configuration.ContextKeyC
14801487
onboarding := c.Onboarding.ToDatabaseModel()
14811488
accreditation := c.Accreditation.ToDatabaseModel()
14821489
autovoucher := c.AutoVoucher.ToDatabaseModel()
1490+
idnow := c.IDNow.ToDatabaseModel()
14831491

14841492
return configuration.ContextKeyConfiguration{
14851493
IdentificationURI: c.IdentificationURI,
14861494
Onboarding: onboarding,
14871495
Accreditation: accreditation,
14881496
AutoVoucher: autovoucher,
1497+
IDNow: idnow,
14891498
}
14901499
}
14911500

@@ -1585,3 +1594,27 @@ func (c *CtxKeyAutoVoucherRepresentation) Validate() error {
15851594
ValidateParameterRegExp("billedRealm", c.BilledRealm, constants.RegExpRealmName, false).
15861595
Status()
15871596
}
1597+
1598+
// ConvertToAPIContextKeyIDNow converts context key idnow configuration from database model to API model
1599+
func ConvertToAPIContextKeyIDNow(idnowCfg *configuration.ContextKeyConfIDNow) CtxKeyIDNowRepresentation {
1600+
if idnowCfg == nil {
1601+
return CtxKeyIDNowRepresentation{}
1602+
}
1603+
return CtxKeyIDNowRepresentation{
1604+
DesktopRedirectURI: idnowCfg.DesktopRedirectURI,
1605+
}
1606+
}
1607+
1608+
// ToDatabaseModel converts a context key autovoucher configuration to the database model
1609+
func (c *CtxKeyIDNowRepresentation) ToDatabaseModel() *configuration.ContextKeyConfIDNow {
1610+
return &configuration.ContextKeyConfIDNow{
1611+
DesktopRedirectURI: c.DesktopRedirectURI,
1612+
}
1613+
}
1614+
1615+
// Validate is a validator for CtxKeyAutoVoucherRepresentation
1616+
func (c *CtxKeyIDNowRepresentation) Validate() error {
1617+
return validation.NewParameterValidator().
1618+
ValidateParameterRegExp("desktopRedirectUri", c.DesktopRedirectURI, constants.RegExpRedirectURI, false).
1619+
Status()
1620+
}

api/management/api_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,7 @@ func TestContextKeyConvertions(t *testing.T) {
12771277
IdentificationURI: nil,
12781278
AutoVoucher: &configuration.ContextKeyConfAutovoucher{},
12791279
Accreditation: &configuration.ContextKeyConfAccreditation{},
1280+
IDNow: &configuration.ContextKeyConfIDNow{},
12801281
})
12811282
assert.Nil(t, config.Accreditation.EmailThemeRealm)
12821283
assert.Nil(t, config.AutoVoucher.ServiceType)
@@ -1287,6 +1288,7 @@ func TestContextKeyConvertions(t *testing.T) {
12871288
assert.Nil(t, config.Onboarding.ClientID)
12881289
assert.Nil(t, config.Onboarding.RedirectURI)
12891290
assert.Nil(t, config.Onboarding.IsRedirectMode)
1291+
assert.Nil(t, config.IDNow.DesktopRedirectURI)
12901292
})
12911293

12921294
t.Run("Config fields are nil empty config", func(t *testing.T) {
@@ -1300,6 +1302,7 @@ func TestContextKeyConvertions(t *testing.T) {
13001302
assert.Nil(t, config.Onboarding.ClientID)
13011303
assert.Nil(t, config.Onboarding.RedirectURI)
13021304
assert.Nil(t, config.Onboarding.IsRedirectMode)
1305+
assert.Nil(t, config.IDNow.DesktopRedirectURI)
13031306
})
13041307
}
13051308

@@ -1524,3 +1527,33 @@ func TestConvertToThemeConfiguration(t *testing.T) {
15241527
assert.Equal(t, expectedFavicon, *res.Favicon)
15251528
})
15261529
}
1530+
1531+
func TestContextKeyIDNowConversions(t *testing.T) {
1532+
idnowConfig := configuration.ContextKeyConfIDNow{
1533+
DesktopRedirectURI: ptr("http://redirect.uri/after/idnow"),
1534+
}
1535+
1536+
apiConfig := ConvertToAPIContextKeyIDNow(&idnowConfig)
1537+
assert.Equal(t, idnowConfig.DesktopRedirectURI, apiConfig.DesktopRedirectURI)
1538+
1539+
dbConfig := apiConfig.ToDatabaseModel()
1540+
assert.Equal(t, idnowConfig.DesktopRedirectURI, dbConfig.DesktopRedirectURI)
1541+
}
1542+
1543+
func TestValidateCtxKeyIDNowRepresentation(t *testing.T) {
1544+
t.Run("Valid configuration", func(t *testing.T) {
1545+
config := configuration.ContextKeyConfIDNow{
1546+
DesktopRedirectURI: ptr("http://redirect.uri?theme=mytheme"),
1547+
}
1548+
apiConfig := ConvertToAPIContextKeyIDNow(&config)
1549+
assert.Nil(t, apiConfig.Validate())
1550+
})
1551+
1552+
t.Run("Invalid configuration", func(t *testing.T) {
1553+
config := configuration.ContextKeyConfIDNow{
1554+
DesktopRedirectURI: ptr("not.a.valid.uri"),
1555+
}
1556+
apiConfig := ConvertToAPIContextKeyIDNow(&config)
1557+
assert.NotNil(t, apiConfig.Validate())
1558+
})
1559+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cloudtrust/keycloak-bridge
33
go 1.25.3
44

55
require (
6-
github.com/cloudtrust/common-service/v2 v2.16.0
6+
github.com/cloudtrust/common-service/v2 v2.16.1
77
github.com/cloudtrust/httpclient v1.6.0
88
github.com/cloudtrust/kafka-client v1.7.2
99
github.com/cloudtrust/keycloak-client/v2 v2.17.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
66
github.com/IBM/sarama v1.46.3/go.mod h1:GTUYiF9DMOZVe3FwyGT+dtSPceGFIgA+sPc5u6CBwko=
77
github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE=
88
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
9-
github.com/cloudtrust/common-service/v2 v2.16.0 h1:1ckA+qKOODQj6ygkH0x0qZogk4HmF1DO2UD6g4zOG5M=
10-
github.com/cloudtrust/common-service/v2 v2.16.0/go.mod h1:2cFLwdEsh2D4mS3mq4K8qWoTYBRLp/gKtTuSP2nglW8=
9+
github.com/cloudtrust/common-service/v2 v2.16.1 h1:rH0CE78Xr5m+R6FDY1X1ApeHiDtMYMadt7zeF4xmeMM=
10+
github.com/cloudtrust/common-service/v2 v2.16.1/go.mod h1:2cFLwdEsh2D4mS3mq4K8qWoTYBRLp/gKtTuSP2nglW8=
1111
github.com/cloudtrust/httpclient v1.6.0 h1:/E/y2wZNyUIjADbP3RLI2pLTWdNvcFSLe1MeRD6RlN4=
1212
github.com/cloudtrust/httpclient v1.6.0/go.mod h1:CK0idOHAQ2CiN2GFOwIYP5hDl2tfUgGdTI9n7Ygbnrs=
1313
github.com/cloudtrust/kafka-client v1.7.2 h1:wezQkWb4nMA2u6PP+x8e54GrZTvEOHQkFuyOziB7Ea0=

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ github.com/IBM/sarama
88
# github.com/VividCortex/gohistogram v1.0.0
99
## explicit
1010
github.com/VividCortex/gohistogram
11-
# github.com/cloudtrust/common-service/v2 v2.16.0
11+
# github.com/cloudtrust/common-service/v2 v2.16.1
1212
## explicit; go 1.25.3
1313
github.com/cloudtrust/common-service/v2
1414
github.com/cloudtrust/common-service/v2/configuration

0 commit comments

Comments
 (0)