Validate checks that the ClientCredentials are properly configured. It ensures that: - ClientID is not empty. - At most one authentication method is configured. - If ClientSecretAuth is set, ClientSecret is not empty.
()
| 35 | // - At most one authentication method is configured. |
| 36 | // - If ClientSecretAuth is set, ClientSecret is not empty. |
| 37 | func (c *ClientCredentials) Validate() error { |
| 38 | if c.ClientID == "" { |
| 39 | return errors.New("ClientID is required") |
| 40 | } |
| 41 | |
| 42 | // Count how many auth methods are configured. |
| 43 | authMethodCount := 0 |
| 44 | if c.ClientSecretAuth != nil { |
| 45 | authMethodCount++ |
| 46 | if c.ClientSecretAuth.ClientSecret == "" { |
| 47 | return errors.New("ClientSecret is required when using ClientSecretAuth") |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // Allow zero auth methods (public client) or exactly one auth method. |
| 52 | if authMethodCount > 1 { |
| 53 | return errors.New("only one client authentication method can be configured") |
| 54 | } |
| 55 | |
| 56 | return nil |
| 57 | } |
no outgoing calls