Skip to content

[extension/oauth2clientauthextension] Allow exporting of OAuth extension to re-use it in other components, required for #39248 #39514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions extension/oauth2clientauthextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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())
Expand All @@ -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,
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down
Loading