Skip to content

Commit

Permalink
auth/azure: fix token exchange url construction
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
aryan9600 committed Dec 4, 2023
1 parent b6693ef commit f7cf46a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions auth/azure/acr_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"io"
"net/http"
"net/url"
"path"
"strings"
"time"

Expand Down Expand Up @@ -101,12 +100,19 @@ func newExchanger(endpoint string) *exchanger {
// ExchangeACRAccessToken exchanges an access token for a refresh token with the
// exchange service.
func (e *exchanger) ExchangeACRAccessToken(armToken string) (string, error) {
// This hack is required because the net/url package does not recognize
// a hostname unless the scheme is also present and it includes the
// entire hostname in the path as well.
if !strings.HasPrefix(e.endpoint, "https://") {
e.endpoint = fmt.Sprintf("https://%s", e.endpoint)
}

// Construct the exchange URL.
exchangeURL, err := url.Parse(e.endpoint)
if err != nil {
return "", err
}
exchangeURL.Path = path.Join(exchangeURL.Path, "oauth2/exchange")
exchangeURL.Path = "oauth2/exchange"

parameters := url.Values{}
parameters.Add("grant_type", "access_token")
Expand Down
1 change: 1 addition & 0 deletions auth/azure/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
_ "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
Expand Down

0 comments on commit f7cf46a

Please sign in to comment.