Skip to content

Commit d322eef

Browse files
Fix id token storing for apps
1 parent eb15732 commit d322eef

1 file changed

Lines changed: 49 additions & 10 deletions

File tree

backend/internal/application/store.go

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ type oAuthConfig struct {
4444

4545
// oAuthTokenConfig represents the OAuth token configuration structure for JSON marshaling/unmarshaling.
4646
type oAuthTokenConfig struct {
47-
AccessToken *tokenConfig `json:"access_token,omitempty"`
47+
Issuer string `json:"issuer,omitempty"`
48+
AccessToken *tokenConfig `json:"access_token,omitempty"`
49+
IDToken *idTokenConfig `json:"id_token,omitempty"`
4850
}
4951

5052
// tokenConfig represents the token configuration structure for JSON marshaling/unmarshaling.
@@ -54,6 +56,13 @@ type tokenConfig struct {
5456
UserAttributes []string `json:"user_attributes,omitempty"`
5557
}
5658

59+
// idTokenConfig represents the ID token configuration structure for JSON marshaling/unmarshaling.
60+
type idTokenConfig struct {
61+
ValidityPeriod int64 `json:"validity_period,omitempty"`
62+
UserAttributes []string `json:"user_attributes,omitempty"`
63+
ScopeClaims map[string][]string `json:"scope_claims,omitempty"`
64+
}
65+
5766
// ApplicationStoreInterface defines the interface for application data persistence operations.
5867
type applicationStoreInterface interface {
5968
CreateApplication(app model.ApplicationProcessedDTO) error
@@ -216,13 +225,23 @@ func (st *applicationStore) GetOAuthApplication(clientID string) (*model.OAuthAp
216225

217226
// Convert token config if present
218227
var oauthTokenConfig *model.OAuthTokenConfig
219-
if oAuthConfig.Token != nil && oAuthConfig.Token.AccessToken != nil {
228+
if oAuthConfig.Token != nil {
220229
oauthTokenConfig = &model.OAuthTokenConfig{
221-
AccessToken: &model.TokenConfig{
230+
Issuer: oAuthConfig.Token.Issuer,
231+
}
232+
if oAuthConfig.Token.AccessToken != nil {
233+
oauthTokenConfig.AccessToken = &model.TokenConfig{
222234
Issuer: oAuthConfig.Token.AccessToken.Issuer,
223235
ValidityPeriod: oAuthConfig.Token.AccessToken.ValidityPeriod,
224236
UserAttributes: oAuthConfig.Token.AccessToken.UserAttributes,
225-
},
237+
}
238+
}
239+
if oAuthConfig.Token.IDToken != nil {
240+
oauthTokenConfig.IDToken = &model.IDTokenConfig{
241+
ValidityPeriod: oAuthConfig.Token.IDToken.ValidityPeriod,
242+
UserAttributes: oAuthConfig.Token.IDToken.UserAttributes,
243+
ScopeClaims: oAuthConfig.Token.IDToken.ScopeClaims,
244+
}
226245
}
227246
}
228247

@@ -380,13 +399,23 @@ func getOAuthConfigJSONBytes(inboundAuthConfig model.InboundAuthConfigProcessedD
380399
}
381400

382401
// Include token config if present
383-
if inboundAuthConfig.OAuthAppConfig.Token != nil && inboundAuthConfig.OAuthAppConfig.Token.AccessToken != nil {
402+
if inboundAuthConfig.OAuthAppConfig.Token != nil {
384403
oauthConfig.Token = &oAuthTokenConfig{
385-
AccessToken: &tokenConfig{
404+
Issuer: inboundAuthConfig.OAuthAppConfig.Token.Issuer,
405+
}
406+
if inboundAuthConfig.OAuthAppConfig.Token.AccessToken != nil {
407+
oauthConfig.Token.AccessToken = &tokenConfig{
386408
Issuer: inboundAuthConfig.OAuthAppConfig.Token.AccessToken.Issuer,
387409
ValidityPeriod: inboundAuthConfig.OAuthAppConfig.Token.AccessToken.ValidityPeriod,
388410
UserAttributes: inboundAuthConfig.OAuthAppConfig.Token.AccessToken.UserAttributes,
389-
},
411+
}
412+
}
413+
if inboundAuthConfig.OAuthAppConfig.Token.IDToken != nil {
414+
oauthConfig.Token.IDToken = &idTokenConfig{
415+
ValidityPeriod: inboundAuthConfig.OAuthAppConfig.Token.IDToken.ValidityPeriod,
416+
UserAttributes: inboundAuthConfig.OAuthAppConfig.Token.IDToken.UserAttributes,
417+
ScopeClaims: inboundAuthConfig.OAuthAppConfig.Token.IDToken.ScopeClaims,
418+
}
390419
}
391420
}
392421

@@ -611,13 +640,23 @@ func buildApplicationFromResultRow(row map[string]interface{}) (model.Applicatio
611640

612641
// Extract token config from OAuth config if present
613642
var oauthTokenConfig *model.OAuthTokenConfig
614-
if oauthConfig.Token != nil && oauthConfig.Token.AccessToken != nil {
643+
if oauthConfig.Token != nil {
615644
oauthTokenConfig = &model.OAuthTokenConfig{
616-
AccessToken: &model.TokenConfig{
645+
Issuer: oauthConfig.Token.Issuer,
646+
}
647+
if oauthConfig.Token.AccessToken != nil {
648+
oauthTokenConfig.AccessToken = &model.TokenConfig{
617649
Issuer: oauthConfig.Token.AccessToken.Issuer,
618650
ValidityPeriod: oauthConfig.Token.AccessToken.ValidityPeriod,
619651
UserAttributes: oauthConfig.Token.AccessToken.UserAttributes,
620-
},
652+
}
653+
}
654+
if oauthConfig.Token.IDToken != nil {
655+
oauthTokenConfig.IDToken = &model.IDTokenConfig{
656+
ValidityPeriod: oauthConfig.Token.IDToken.ValidityPeriod,
657+
UserAttributes: oauthConfig.Token.IDToken.UserAttributes,
658+
ScopeClaims: oauthConfig.Token.IDToken.ScopeClaims,
659+
}
621660
}
622661
}
623662

0 commit comments

Comments
 (0)