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 a7cc163
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 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,20 @@ 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) {
// If the endpoint doesn't have a scheme, then prepend the "https" scheme.
// This is required because the net/url package cannot parse an URL properly
// without a scheme causing issues such as returning an URL object with an
// empty host.
if !(strings.HasPrefix(e.endpoint, "https://") || strings.HasPrefix(e.endpoint, "http://")) {
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 a7cc163

Please sign in to comment.