From d4421e7ce6481770227e1219bd27f430b039b859 Mon Sep 17 00:00:00 2001 From: Schm1tz1 Date: Mon, 21 Apr 2025 13:43:59 +0200 Subject: [PATCH] Exporting Oauth2 client authenticator so we can re-use the functionality in other exporters/receivers. --- .../oauth2clientauthextension/extension.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extension/oauth2clientauthextension/extension.go b/extension/oauth2clientauthextension/extension.go index f6725084bbc0b..3301ee8545acc 100644 --- a/extension/oauth2clientauthextension/extension.go +++ b/extension/oauth2clientauthextension/extension.go @@ -21,14 +21,14 @@ import ( ) var ( - _ extension.Extension = (*clientAuthenticator)(nil) - _ extensionauth.HTTPClient = (*clientAuthenticator)(nil) - _ extensionauth.GRPCClient = (*clientAuthenticator)(nil) + _ extension.Extension = (*OauthClientAuthenticator)(nil) + _ extensionauth.HTTPClient = (*OauthClientAuthenticator)(nil) + _ extensionauth.GRPCClient = (*OauthClientAuthenticator)(nil) ) -// clientAuthenticator provides implementation for providing client authentication using OAuth2 client credentials +// OauthClientAuthenticator provides implementation for providing client authentication using OAuth2 client credentials // workflow for both gRPC and HTTP clients. -type clientAuthenticator struct { +type OauthClientAuthenticator struct { component.StartFunc component.ShutdownFunc @@ -48,7 +48,7 @@ var _ oauth2.TokenSource = (*errorWrappingTokenSource)(nil) // errFailedToGetSecurityToken indicates a problem communicating with OAuth2 server. var errFailedToGetSecurityToken = errors.New("failed to get security token from token endpoint") -func newClientAuthenticator(cfg *Config, logger *zap.Logger) (*clientAuthenticator, error) { +func newClientAuthenticator(cfg *Config, logger *zap.Logger) (*OauthClientAuthenticator, error) { transport := http.DefaultTransport.(*http.Transport).Clone() tlsCfg, err := cfg.TLSSetting.LoadTLSConfig(context.Background()) @@ -57,7 +57,7 @@ func newClientAuthenticator(cfg *Config, logger *zap.Logger) (*clientAuthenticat } transport.TLSClientConfig = tlsCfg - return &clientAuthenticator{ + return &OauthClientAuthenticator{ clientCredentials: &clientCredentialsConfig{ Config: clientcredentials.Config{ ClientID: cfg.ClientID, @@ -90,7 +90,7 @@ func (ewts errorWrappingTokenSource) Token() (*oauth2.Token, error) { // RoundTripper returns oauth2.Transport, an http.RoundTripper that performs "client-credential" OAuth flow and // also auto refreshes OAuth tokens as needed. -func (o *clientAuthenticator) RoundTripper(base http.RoundTripper) (http.RoundTripper, error) { +func (o *OauthClientAuthenticator) RoundTripper(base http.RoundTripper) (http.RoundTripper, error) { ctx := context.WithValue(context.Background(), oauth2.HTTPClient, o.client) return &oauth2.Transport{ Source: errorWrappingTokenSource{ @@ -103,7 +103,7 @@ func (o *clientAuthenticator) RoundTripper(base http.RoundTripper) (http.RoundTr // PerRPCCredentials returns gRPC PerRPCCredentials that supports "client-credential" OAuth flow. The underneath // oauth2.clientcredentials.Config instance will manage tokens performing auto refresh as necessary. -func (o *clientAuthenticator) PerRPCCredentials() (credentials.PerRPCCredentials, error) { +func (o *OauthClientAuthenticator) PerRPCCredentials() (credentials.PerRPCCredentials, error) { ctx := context.WithValue(context.Background(), oauth2.HTTPClient, o.client) return grpcOAuth.TokenSource{ TokenSource: errorWrappingTokenSource{