Skip to content

Commit f7cf46a

Browse files
committed
auth/azure: fix token exchange url construction
Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent b6693ef commit f7cf46a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

auth/azure/acr_auth.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"io"
2525
"net/http"
2626
"net/url"
27-
"path"
2827
"strings"
2928
"time"
3029

@@ -101,12 +100,19 @@ func newExchanger(endpoint string) *exchanger {
101100
// ExchangeACRAccessToken exchanges an access token for a refresh token with the
102101
// exchange service.
103102
func (e *exchanger) ExchangeACRAccessToken(armToken string) (string, error) {
103+
// This hack is required because the net/url package does not recognize
104+
// a hostname unless the scheme is also present and it includes the
105+
// entire hostname in the path as well.
106+
if !strings.HasPrefix(e.endpoint, "https://") {
107+
e.endpoint = fmt.Sprintf("https://%s", e.endpoint)
108+
}
109+
104110
// Construct the exchange URL.
105111
exchangeURL, err := url.Parse(e.endpoint)
106112
if err != nil {
107113
return "", err
108114
}
109-
exchangeURL.Path = path.Join(exchangeURL.Path, "oauth2/exchange")
115+
exchangeURL.Path = "oauth2/exchange"
110116

111117
parameters := url.Values{}
112118
parameters.Add("grant_type", "access_token")

auth/azure/resource_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
23+
_ "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime"
2324
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
2425
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
2526
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"

0 commit comments

Comments
 (0)