validateGrantTypes validates OAuth2 grant types
(grantTypes []OAuth2ProviderGrantType)
| 186 | |
| 187 | // validateGrantTypes validates OAuth2 grant types |
| 188 | func validateGrantTypes(grantTypes []OAuth2ProviderGrantType) error { |
| 189 | for _, grant := range grantTypes { |
| 190 | if !isSupportedGrantType(grant) { |
| 191 | return xerrors.Errorf("unsupported grant type: %s", grant) |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // Ensure authorization_code is present if redirect_uris are specified |
| 196 | hasAuthCode := slices.Contains(grantTypes, OAuth2ProviderGrantTypeAuthorizationCode) |
| 197 | if !hasAuthCode { |
| 198 | return xerrors.New("authorization_code grant type is required when redirect_uris are specified") |
| 199 | } |
| 200 | |
| 201 | return nil |
| 202 | } |
| 203 | |
| 204 | func isSupportedGrantType(grant OAuth2ProviderGrantType) bool { |
| 205 | switch grant { |
no test coverage detected