MCPcopy Index your code
hub / github.com/coder/coder / validateGrantTypes

Function validateGrantTypes

codersdk/oauth2_validation.go:188–202  ·  view source on GitHub ↗

validateGrantTypes validates OAuth2 grant types

(grantTypes []OAuth2ProviderGrantType)

Source from the content-addressed store, hash-verified

186
187// validateGrantTypes validates OAuth2 grant types
188func 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
204func isSupportedGrantType(grant OAuth2ProviderGrantType) bool {
205 switch grant {

Callers 1

ValidateMethod · 0.85

Calls 4

isSupportedGrantTypeFunction · 0.85
NewMethod · 0.65
ErrorfMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected