-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support provider specific handling (#118)
Adds a provider_config field and initial interface definitions to allow for custom provider config handling. Co-authored-by: Jim Kalafut <jkalafut@hashicorp.com> Co-authored-by: Clint <catsby@users.noreply.github.com>
- Loading branch information
1 parent
175b36b
commit 71af593
Showing
33 changed files
with
6,411 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package jwtauth | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// Provider-specific configuration interfaces | ||
// All providers must implement the CustomProvider interface, and may implement | ||
// others as needed. | ||
|
||
// ProviderMap returns a map of provider names to custom types | ||
func ProviderMap() map[string]CustomProvider { | ||
return map[string]CustomProvider{ | ||
// TODO: remove "empty" provider when actual providers are added | ||
"empty": &EmptyProvider{}, | ||
} | ||
} | ||
|
||
// CustomProvider - Any custom provider must implement this interface | ||
type CustomProvider interface { | ||
// Initialize should validate jwtConfig.ProviderConfig, set internal values | ||
// and run any initialization necessary for subsequent calls to interface | ||
// functions the provider implements | ||
Initialize(*jwtConfig) error | ||
|
||
// SensitiveKeys returns any fields in a provider's jwtConfig.ProviderConfig | ||
// that should be masked or omitted when output | ||
SensitiveKeys() []string | ||
} | ||
|
||
// NewProviderConfig - returns appropriate provider struct if provider_config is | ||
// specified in jwtConfig. The provider map is provider name -to- instance of a | ||
// CustomProvider. | ||
func NewProviderConfig(jc *jwtConfig, providerMap map[string]CustomProvider) (CustomProvider, error) { | ||
if len(jc.ProviderConfig) == 0 { | ||
return nil, nil | ||
} | ||
provider, ok := jc.ProviderConfig["provider"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("'provider' field not found in provider_config") | ||
} | ||
newCustomProvider, ok := providerMap[provider] | ||
if !ok { | ||
return nil, fmt.Errorf("provider %q not found in custom providers", provider) | ||
} | ||
if err := newCustomProvider.Initialize(jc); err != nil { | ||
return nil, fmt.Errorf("error initializing %q provider_config: %s", provider, err) | ||
} | ||
return newCustomProvider, nil | ||
} | ||
|
||
// Example interfaces that are implemented by one or more provider types | ||
// // UserInfoFetcher - Optional support for custom UserInfo handling | ||
// type UserInfoFetcher interface { | ||
// FetchUserInfo(context.Context, *oidc.Provider, *oauth2.Token, claims) error | ||
// } | ||
|
||
// // GroupsFetcher - Optional support for custom groups handling | ||
// type GroupsFetcher interface { | ||
// FetchGroups(context.Context, *oauth2.Token, claims) error | ||
// } |
Oops, something went wrong.