@@ -38,11 +38,15 @@ const (
3838 spEntityIDKey = "spConfig.spEntityId"
3939 callbackURIKey = "spConfig.callbackUri"
4040
41- clientIDKey = "clientId"
42- issuerKey = "issuer"
41+ clientIDKey = "clientId"
42+ clientSecretKey = "clientSecret"
43+ issuerKey = "issuer"
4344
4445 displayNameKey = "displayName"
4546 enabledKey = "enabled"
47+
48+ idTokenResponseTypeKey = "responseType.idToken"
49+ codeResponseTypeKey = "responseType.code"
4650)
4751
4852type nestedMap map [string ]interface {}
@@ -113,11 +117,14 @@ func buildMask(data map[string]interface{}) []string {
113117// OIDCProviderConfig is the OIDC auth provider configuration.
114118// See https://openid.net/specs/openid-connect-core-1_0-final.html.
115119type OIDCProviderConfig struct {
116- ID string
117- DisplayName string
118- Enabled bool
119- ClientID string
120- Issuer string
120+ ID string
121+ DisplayName string
122+ Enabled bool
123+ ClientID string
124+ Issuer string
125+ ClientSecret string
126+ CodeResponseType bool
127+ IDTokenResponseType bool
121128}
122129
123130// OIDCProviderConfigToCreate represents the options used to create a new OIDCProviderConfig.
@@ -152,6 +159,27 @@ func (config *OIDCProviderConfigToCreate) Enabled(enabled bool) *OIDCProviderCon
152159 return config .set (enabledKey , enabled )
153160}
154161
162+ // ClientSecret sets the client secret for the new provider.
163+ // This is required for the code flow.
164+ func (config * OIDCProviderConfigToCreate ) ClientSecret (secret string ) * OIDCProviderConfigToCreate {
165+ return config .set (clientSecretKey , secret )
166+ }
167+
168+ // IDTokenResponseType sets whether to enable the ID token response flow for the new provider.
169+ // By default, this is enabled if no response type is specified.
170+ // Having both the code and ID token response flows is currently not supported.
171+ func (config * OIDCProviderConfigToCreate ) IDTokenResponseType (enabled bool ) * OIDCProviderConfigToCreate {
172+ return config .set (idTokenResponseTypeKey , enabled )
173+ }
174+
175+ // CodeResponseType sets whether to enable the code response flow for the new provider.
176+ // By default, this is not enabled if no response type is specified.
177+ // A client secret must be set for this response type.
178+ // Having both the code and ID token response flows is currently not supported.
179+ func (config * OIDCProviderConfigToCreate ) CodeResponseType (enabled bool ) * OIDCProviderConfigToCreate {
180+ return config .set (codeResponseTypeKey , enabled )
181+ }
182+
155183func (config * OIDCProviderConfigToCreate ) set (key string , value interface {}) * OIDCProviderConfigToCreate {
156184 if config .params == nil {
157185 config .params = make (nestedMap )
@@ -180,6 +208,19 @@ func (config *OIDCProviderConfigToCreate) buildRequest() (nestedMap, string, err
180208 return nil , "" , fmt .Errorf ("failed to parse Issuer: %v" , err )
181209 }
182210
211+ if val , ok := config .params .Get (codeResponseTypeKey ); ok && val .(bool ) {
212+ if val , ok := config .params .GetString (clientSecretKey ); ! ok || val == "" {
213+ return nil , "" , errors .New ("Client Secret must not be empty for Code Response Type" )
214+ }
215+ if val , ok := config .params .Get (idTokenResponseTypeKey ); ok && val .(bool ) {
216+ return nil , "" , errors .New ("Only one response type may be chosen" )
217+ }
218+ } else if ok && ! val .(bool ) {
219+ if val , ok := config .params .Get (idTokenResponseTypeKey ); ok && ! val .(bool ) {
220+ return nil , "" , errors .New ("At least one response type must be returned" )
221+ }
222+ }
223+
183224 return config .params , config .id , nil
184225}
185226
@@ -213,6 +254,27 @@ func (config *OIDCProviderConfigToUpdate) Enabled(enabled bool) *OIDCProviderCon
213254 return config .set (enabledKey , enabled )
214255}
215256
257+ // ClientSecret sets the client secret for the provider.
258+ // This is required for the code flow.
259+ func (config * OIDCProviderConfigToUpdate ) ClientSecret (secret string ) * OIDCProviderConfigToUpdate {
260+ return config .set (clientSecretKey , secret )
261+ }
262+
263+ // IDTokenResponseType sets whether to enable the ID token response flow for the provider.
264+ // By default, this is enabled if no response type is specified.
265+ // Having both the code and ID token response flows is currently not supported.
266+ func (config * OIDCProviderConfigToUpdate ) IDTokenResponseType (enabled bool ) * OIDCProviderConfigToUpdate {
267+ return config .set (idTokenResponseTypeKey , enabled )
268+ }
269+
270+ // CodeResponseType sets whether to enable the code response flow for the new provider.
271+ // By default, this is not enabled if no response type is specified.
272+ // A client secret must be set for this response type.
273+ // Having both the code and ID token response flows is currently not supported.
274+ func (config * OIDCProviderConfigToUpdate ) CodeResponseType (enabled bool ) * OIDCProviderConfigToUpdate {
275+ return config .set (codeResponseTypeKey , enabled )
276+ }
277+
216278func (config * OIDCProviderConfigToUpdate ) set (key string , value interface {}) * OIDCProviderConfigToUpdate {
217279 if config .params == nil {
218280 config .params = make (nestedMap )
@@ -240,6 +302,19 @@ func (config *OIDCProviderConfigToUpdate) buildRequest() (nestedMap, error) {
240302 }
241303 }
242304
305+ if val , ok := config .params .Get (codeResponseTypeKey ); ok && val .(bool ) {
306+ if val , ok := config .params .GetString (clientSecretKey ); ! ok || val == "" {
307+ return nil , errors .New ("Client Secret must not be empty for Code Response Type" )
308+ }
309+ if val , ok := config .params .Get (idTokenResponseTypeKey ); ok && val .(bool ) {
310+ return nil , errors .New ("Only one response type may be chosen" )
311+ }
312+ } else if ok && ! val .(bool ) {
313+ if val , ok := config .params .Get (idTokenResponseTypeKey ); ok && ! val .(bool ) {
314+ return nil , errors .New ("At least one response type must be returned" )
315+ }
316+ }
317+
243318 return config .params , nil
244319}
245320
@@ -826,20 +901,30 @@ func (c *baseClient) makeRequest(
826901}
827902
828903type oidcProviderConfigDAO struct {
829- Name string `json:"name"`
830- ClientID string `json:"clientId"`
831- Issuer string `json:"issuer"`
832- DisplayName string `json:"displayName"`
833- Enabled bool `json:"enabled"`
904+ Name string `json:"name"`
905+ ClientID string `json:"clientId"`
906+ Issuer string `json:"issuer"`
907+ DisplayName string `json:"displayName"`
908+ Enabled bool `json:"enabled"`
909+ ClientSecret string `json:"clientSecret"`
910+ ResponseType oidcProviderResponseType `json:"responseType"`
911+ }
912+
913+ type oidcProviderResponseType struct {
914+ Code bool `json:"code"`
915+ IDToken bool `json:"idToken"`
834916}
835917
836918func (dao * oidcProviderConfigDAO ) toOIDCProviderConfig () * OIDCProviderConfig {
837919 return & OIDCProviderConfig {
838- ID : extractResourceID (dao .Name ),
839- DisplayName : dao .DisplayName ,
840- Enabled : dao .Enabled ,
841- ClientID : dao .ClientID ,
842- Issuer : dao .Issuer ,
920+ ID : extractResourceID (dao .Name ),
921+ DisplayName : dao .DisplayName ,
922+ Enabled : dao .Enabled ,
923+ ClientID : dao .ClientID ,
924+ Issuer : dao .Issuer ,
925+ ClientSecret : dao .ClientSecret ,
926+ CodeResponseType : dao .ResponseType .Code ,
927+ IDTokenResponseType : dao .ResponseType .IDToken ,
843928 }
844929}
845930
0 commit comments