Skip to content

Commit

Permalink
Update token source provider to optionally call GetPublicClientConfig (
Browse files Browse the repository at this point in the history
…#326)

* Update token source provider

Signed-off-by: Katrina Rogan <[email protected]>

* GH actions incident

Signed-off-by: Katrina Rogan <[email protected]>

Signed-off-by: Katrina Rogan <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
  • Loading branch information
katrogan authored and eapolinario committed Sep 13, 2023
1 parent fb6dc68 commit 45161c5
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions flyteidl/clients/go/admin/token_source_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ func NewTokenSourceProvider(ctx context.Context, cfg *Config, tokenCache cache.T
tokenURL = metadata.TokenEndpoint
}

clientMetadata, err := authClient.GetPublicClientConfig(ctx, &service.PublicClientAuthConfigRequest{})
if err != nil {
return nil, fmt.Errorf("failed to fetch client metadata. Error: %v", err)
scopes := cfg.Scopes
if len(scopes) == 0 {
clientMetadata, err := authClient.GetPublicClientConfig(ctx, &service.PublicClientAuthConfigRequest{})
if err != nil {
return nil, fmt.Errorf("failed to fetch client metadata. Error: %v", err)
}
scopes = clientMetadata.Scopes
}

tokenProvider, err = NewClientCredentialsTokenSourceProvider(ctx, cfg, clientMetadata, tokenURL)
tokenProvider, err = NewClientCredentialsTokenSourceProvider(ctx, cfg, scopes, tokenURL)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -148,8 +152,7 @@ type ClientCredentialsTokenSourceProvider struct {
TokenRefreshWindow time.Duration
}

func NewClientCredentialsTokenSourceProvider(ctx context.Context, cfg *Config,
clientMetadata *service.PublicClientAuthConfigResponse, tokenURL string) (TokenSourceProvider, error) {
func NewClientCredentialsTokenSourceProvider(ctx context.Context, cfg *Config, scopes []string, tokenURL string) (TokenSourceProvider, error) {
var secret string
if len(cfg.ClientSecretEnvVar) > 0 {
secret = os.Getenv(cfg.ClientSecretEnvVar)
Expand All @@ -162,11 +165,6 @@ func NewClientCredentialsTokenSourceProvider(ctx context.Context, cfg *Config,
secret = string(secretBytes)
}
secret = strings.TrimSpace(secret)

scopes := cfg.Scopes
if len(scopes) == 0 {
scopes = clientMetadata.Scopes
}
return ClientCredentialsTokenSourceProvider{
ccConfig: clientcredentials.Config{
ClientID: cfg.ClientID,
Expand Down

0 comments on commit 45161c5

Please sign in to comment.