Skip to content

Commit 9c1f0c4

Browse files
Alevskdvaldivia
andauthored
Custom HTTP Client TLS transport for STSWebIdentity (#612)
Co-authored-by: Daniel Valdivia <hola@danielvaldivia.com>
1 parent 6ac95e4 commit 9c1f0c4

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

pkg/auth/idp/oauth2/provider.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ type Provider struct {
9191
// often available via site-specific packages, such as
9292
// google.Endpoint or github.Endpoint.
9393
// - Scopes specifies optional requested permissions.
94-
ClientID string
95-
oauth2Config Configuration
96-
oidcProvider *oidc.Provider
94+
ClientID string
95+
oauth2Config Configuration
96+
oidcProvider *oidc.Provider
97+
provHTTPClient *http.Client
9798
}
9899

99100
// derivedKey is the key used to compute the HMAC for signing the oauth state parameter
@@ -103,8 +104,9 @@ var derivedKey = pbkdf2.Key([]byte(getPassphraseForIdpHmac()), []byte(getSaltFor
103104
// NewOauth2ProviderClient instantiates a new oauth2 client using the configured credentials
104105
// it returns a *Provider object that contains the necessary configuration to initiate an
105106
// oauth2 authentication flow
106-
func NewOauth2ProviderClient(ctx context.Context, scopes []string) (*Provider, error) {
107-
provider, err := oidc.NewProvider(ctx, GetIdpURL())
107+
func NewOauth2ProviderClient(ctx context.Context, scopes []string, httpClient *http.Client) (*Provider, error) {
108+
customCtx := oidc.ClientContext(ctx, httpClient)
109+
provider, err := oidc.NewProvider(customCtx, GetIdpURL())
108110
if err != nil {
109111
return nil, err
110112
}
@@ -122,6 +124,7 @@ func NewOauth2ProviderClient(ctx context.Context, scopes []string) (*Provider, e
122124
}
123125
client.oidcProvider = provider
124126
client.ClientID = GetIdpClientID()
127+
client.provHTTPClient = httpClient
125128

126129
return client, nil
127130
}
@@ -172,10 +175,11 @@ func (client *Provider) VerifyIdentity(ctx context.Context, code, state string)
172175
}, nil
173176
}
174177
stsEndpoint := GetSTSEndpoint()
175-
sts, err := credentials.NewSTSWebIdentity(stsEndpoint, getWebTokenExpiry)
176-
if err != nil {
177-
return nil, err
178-
}
178+
sts := credentials.New(&credentials.STSWebIdentity{
179+
Client: client.provHTTPClient,
180+
STSEndpoint: stsEndpoint,
181+
GetWebIDTokenExpiry: getWebTokenExpiry,
182+
})
179183
return sts, nil
180184
}
181185

restapi/user_login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func getLoginDetailsResponse() (*models.LoginDetails, *models.Error) {
187187
if oauth2.IsIdpEnabled() {
188188
loginStrategy = models.LoginDetailsLoginStrategyRedirect
189189
// initialize new oauth2 client
190-
oauth2Client, err := oauth2.NewOauth2ProviderClient(ctx, nil)
190+
oauth2Client, err := oauth2.NewOauth2ProviderClient(ctx, nil, GetConsoleSTSClient())
191191
if err != nil {
192192
return nil, prepareError(err)
193193
}
@@ -235,7 +235,7 @@ func getLoginOauth2AuthResponse(lr *models.LoginOauth2AuthRequest) (*models.Logi
235235
return loginResponse, nil
236236
} else if oauth2.IsIdpEnabled() {
237237
// initialize new oauth2 client
238-
oauth2Client, err := oauth2.NewOauth2ProviderClient(ctx, nil)
238+
oauth2Client, err := oauth2.NewOauth2ProviderClient(ctx, nil, GetConsoleSTSClient())
239239
if err != nil {
240240
return nil, prepareError(err)
241241
}

0 commit comments

Comments
 (0)