Skip to content

Commit

Permalink
New constructor if non-default endpoint (#313)
Browse files Browse the repository at this point in the history
Configurable OAuth2 endpoints for ClientCredentialClient
  • Loading branch information
shacker27 authored Mar 1, 2024
1 parent caaa1c2 commit 34f9272
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions oauth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ type oauth2Response struct {
// The client will use the httpclient's configured BaseURIs.
func NewClientCredentialClient(client httpclient.Client) ClientCredentialClient {
return &serviceClient{
client: client,
client: client,
clientCredentialEndpoint: clientCredentialsEndpoint,
}
}

// NewClientCredentialClientWithEndpoint returns an oauth2.Client configured using the provided client and oauth endpoint.
// The client will use the httpclient's configured BaseURIs.
func NewClientCredentialClientWithEndpoint(client httpclient.Client, endpoint string) ClientCredentialClient {
return &serviceClient{
client: client,
clientCredentialEndpoint: endpoint,
}
}

Expand All @@ -63,7 +73,7 @@ func (s *serviceClient) CreateClientCredentialToken(ctx context.Context, clientI
_, err := s.client.Do(ctx,
httpclient.WithRPCMethodName("CreateClientCredentialToken"),
httpclient.WithRequestMethod(http.MethodPost),
httpclient.WithPath(clientCredentialsEndpoint),
httpclient.WithPath(s.clientCredentialEndpoint),
httpclient.WithRequestBody(urlValues, codecs.FormURLEncoded),
httpclient.WithJSONResponse(&oauth2Resp),
httpclient.WithRequestErrorDecoder(errorDecoder{ctx}),
Expand Down

0 comments on commit 34f9272

Please sign in to comment.