diff --git a/sdk/azidentity/aad_identity_client.go b/sdk/azidentity/aad_identity_client.go index 76ef981f2a5f..4c839fe88465 100644 --- a/sdk/azidentity/aad_identity_client.go +++ b/sdk/azidentity/aad_identity_client.go @@ -198,7 +198,7 @@ func (c *aadIdentityClient) createRefreshTokenRequest(ctx context.Context, tenan if err != nil { return nil, err } - if err := req.SetBody(body, azcore.HeaderURLEncoded); err != nil { + if err := req.SetBody(body, headerURLEncoded); err != nil { return nil, err } return req, nil @@ -216,7 +216,7 @@ func (c *aadIdentityClient) createClientSecretAuthRequest(ctx context.Context, t if err != nil { return nil, err } - if err := req.SetBody(body, azcore.HeaderURLEncoded); err != nil { + if err := req.SetBody(body, headerURLEncoded); err != nil { return nil, err } @@ -242,7 +242,7 @@ func (c *aadIdentityClient) createClientCertificateAuthRequest(ctx context.Conte if err != nil { return nil, err } - if err := req.SetBody(body, azcore.HeaderURLEncoded); err != nil { + if err := req.SetBody(body, headerURLEncoded); err != nil { return nil, err } return req, nil @@ -288,7 +288,7 @@ func (c *aadIdentityClient) createUsernamePasswordAuthRequest(ctx context.Contex if err != nil { return nil, err } - if err := req.SetBody(body, azcore.HeaderURLEncoded); err != nil { + if err := req.SetBody(body, headerURLEncoded); err != nil { return nil, err } return req, nil @@ -339,7 +339,7 @@ func (c *aadIdentityClient) createDeviceCodeAuthRequest(ctx context.Context, ten if err != nil { return nil, err } - if err := req.SetBody(body, azcore.HeaderURLEncoded); err != nil { + if err := req.SetBody(body, headerURLEncoded); err != nil { return nil, err } return req, nil @@ -373,7 +373,7 @@ func (c *aadIdentityClient) createDeviceCodeNumberRequest(ctx context.Context, t if err != nil { return nil, err } - if err := req.SetBody(body, azcore.HeaderURLEncoded); err != nil { + if err := req.SetBody(body, headerURLEncoded); err != nil { return nil, err } return req, nil @@ -436,7 +436,7 @@ func (c *aadIdentityClient) createAuthorizationCodeAuthRequest(ctx context.Conte if err != nil { return nil, err } - if err := req.SetBody(body, azcore.HeaderURLEncoded); err != nil { + if err := req.SetBody(body, headerURLEncoded); err != nil { return nil, err } return req, nil diff --git a/sdk/azidentity/aad_identity_client_test.go b/sdk/azidentity/aad_identity_client_test.go index 7a60f16e8b92..3f6806e1e020 100644 --- a/sdk/azidentity/aad_identity_client_test.go +++ b/sdk/azidentity/aad_identity_client_test.go @@ -63,7 +63,7 @@ func TestTelemetryDefaultUserAgent(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Fatalf("unexpected status code: %d", resp.StatusCode) } - if ua := resp.Request.Header.Get(azcore.HeaderUserAgent); !strings.HasPrefix(ua, UserAgent) { + if ua := resp.Request.Header.Get(headerUserAgent); !strings.HasPrefix(ua, UserAgent) { t.Fatalf("unexpected User-Agent %s", ua) } } @@ -92,7 +92,7 @@ func TestTelemetryCustom(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Fatalf("unexpected status code: %d", resp.StatusCode) } - if ua := resp.Request.Header.Get(azcore.HeaderUserAgent); !strings.HasPrefix(ua, customTelemetry+" "+UserAgent) { + if ua := resp.Request.Header.Get(headerUserAgent); !strings.HasPrefix(ua, customTelemetry+" "+UserAgent) { t.Fatalf("unexpected User-Agent %s", ua) } } diff --git a/sdk/azidentity/authorization_code_credential.go b/sdk/azidentity/authorization_code_credential.go index 981f3dc5783b..0a6ea1534547 100644 --- a/sdk/azidentity/authorization_code_credential.go +++ b/sdk/azidentity/authorization_code_credential.go @@ -78,8 +78,8 @@ func (c *AuthorizationCodeCredential) GetToken(ctx context.Context, opts azcore. return tk, nil } -// AuthenticationPolicy implements the azcore.Credential interface on AuthorizationCodeCredential. -func (c *AuthorizationCodeCredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +// NewAuthenticationPolicy implements the azcore.Credential interface on AuthorizationCodeCredential. +func (c *AuthorizationCodeCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c, options) } diff --git a/sdk/azidentity/authorization_code_credential_test.go b/sdk/azidentity/authorization_code_credential_test.go index 15737acceedc..998f7514536a 100644 --- a/sdk/azidentity/authorization_code_credential_test.go +++ b/sdk/azidentity/authorization_code_credential_test.go @@ -43,7 +43,7 @@ func TestAuthorizationCodeCredential_CreateAuthRequestSuccess(t *testing.T) { if err != nil { t.Fatalf("Unexpectedly received an error: %v", err) } - if req.Request.Header.Get(azcore.HeaderContentType) != azcore.HeaderURLEncoded { + if req.Request.Header.Get(headerContentType) != headerURLEncoded { t.Fatal("Unexpected value for Content-Type header") } body, err := ioutil.ReadAll(req.Request.Body) diff --git a/sdk/azidentity/azidentity.go b/sdk/azidentity/azidentity.go index cd335b2756c5..d3d21f7e8bb9 100644 --- a/sdk/azidentity/azidentity.go +++ b/sdk/azidentity/azidentity.go @@ -28,6 +28,15 @@ const ( defaultSuffix = "/.default" ) +const ( + headerXmsDate = "x-ms-date" + headerUserAgent = "User-Agent" + headerURLEncoded = "application/x-www-form-urlencoded" + headerAuthorization = "Authorization" + headerMetadata = "Metadata" + headerContentType = "Content-Type" +) + const tenantIDValidationErr = "Invalid tenantID provided. You can locate your tenantID by following the instructions listed here: https://docs.microsoft.com/partner-center/find-ids-and-domain-names." var ( diff --git a/sdk/azidentity/azure_cli_credential.go b/sdk/azidentity/azure_cli_credential.go index 4e4d0a78c42c..d08c94f0d5a7 100644 --- a/sdk/azidentity/azure_cli_credential.go +++ b/sdk/azidentity/azure_cli_credential.go @@ -68,8 +68,8 @@ func (c *AzureCLICredential) GetToken(ctx context.Context, opts azcore.TokenRequ return at, nil } -// AuthenticationPolicy implements the azcore.Credential interface on AzureCLICredential. -func (c *AzureCLICredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +// NewAuthenticationPolicy implements the azcore.Credential interface on AzureCLICredential. +func (c *AzureCLICredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c, options) } @@ -188,3 +188,5 @@ func parseExpirationDate(input string) (*time.Time, error) { } return &expirationDate, nil } + +var _ azcore.TokenCredential = (*AzureCLICredential)(nil) diff --git a/sdk/azidentity/bearer_token_policy.go b/sdk/azidentity/bearer_token_policy.go index d330afe98cc6..d363c7cb81a6 100644 --- a/sdk/azidentity/bearer_token_policy.go +++ b/sdk/azidentity/bearer_token_policy.go @@ -34,11 +34,11 @@ type bearerTokenPolicy struct { options azcore.TokenRequestOptions } -func newBearerTokenPolicy(creds azcore.TokenCredential, opts azcore.AuthenticationPolicyOptions) *bearerTokenPolicy { +func newBearerTokenPolicy(creds azcore.TokenCredential, opts azcore.AuthenticationOptions) *bearerTokenPolicy { return &bearerTokenPolicy{ cond: sync.NewCond(&sync.Mutex{}), creds: creds, - options: opts.Options, + options: opts.TokenRequest, } } @@ -100,8 +100,8 @@ func (b *bearerTokenPolicy) Do(req *azcore.Request) (*azcore.Response, error) { b.expiresOn = tk.ExpiresOn b.unlock() } - req.Request.Header.Set(azcore.HeaderXmsDate, time.Now().UTC().Format(http.TimeFormat)) - req.Request.Header.Set(azcore.HeaderAuthorization, header) + req.Request.Header.Set(headerXmsDate, time.Now().UTC().Format(http.TimeFormat)) + req.Request.Header.Set(headerAuthorization, header) return req.Next() } diff --git a/sdk/azidentity/bearer_token_policy_test.go b/sdk/azidentity/bearer_token_policy_test.go index c3f2b0991af2..b11c8512d937 100644 --- a/sdk/azidentity/bearer_token_policy_test.go +++ b/sdk/azidentity/bearer_token_policy_test.go @@ -29,7 +29,7 @@ func defaultTestPipeline(srv azcore.Transport, cred azcore.Credential, scope str return azcore.NewPipeline( srv, azcore.NewRetryPolicy(&retryOpts), - cred.AuthenticationPolicy(azcore.AuthenticationPolicyOptions{Options: azcore.TokenRequestOptions{Scopes: []string{scope}}}), + cred.NewAuthenticationPolicy(azcore.AuthenticationOptions{TokenRequest: azcore.TokenRequestOptions{Scopes: []string{scope}}}), azcore.NewLogPolicy(nil)) } @@ -55,7 +55,7 @@ func TestBearerPolicy_SuccessGetToken(t *testing.T) { t.Fatalf("Expected nil error but received one") } const expectedToken = bearerTokenPrefix + tokenValue - if token := resp.Request.Header.Get(azcore.HeaderAuthorization); token != expectedToken { + if token := resp.Request.Header.Get(headerAuthorization); token != expectedToken { t.Fatalf("expected token '%s', got '%s'", expectedToken, token) } } diff --git a/sdk/azidentity/chained_token_credential.go b/sdk/azidentity/chained_token_credential.go index af06decfd221..f02c0c198854 100644 --- a/sdk/azidentity/chained_token_credential.go +++ b/sdk/azidentity/chained_token_credential.go @@ -68,8 +68,8 @@ func (c *ChainedTokenCredential) GetToken(ctx context.Context, opts azcore.Token return nil, credErr } -// AuthenticationPolicy implements the azcore.Credential interface on ChainedTokenCredential and sets the bearer token -func (c *ChainedTokenCredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +// NewAuthenticationPolicy implements the azcore.Credential interface on ChainedTokenCredential and sets the bearer token +func (c *ChainedTokenCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c, options) } @@ -82,3 +82,5 @@ func createChainedErrorMessage(errList []*CredentialUnavailableError) string { return msg } + +var _ azcore.TokenCredential = (*ChainedTokenCredential)(nil) diff --git a/sdk/azidentity/client_certificate_credential.go b/sdk/azidentity/client_certificate_credential.go index edb92471edd3..242a1fa75eb2 100644 --- a/sdk/azidentity/client_certificate_credential.go +++ b/sdk/azidentity/client_certificate_credential.go @@ -216,7 +216,9 @@ func (c *ClientCertificateCredential) GetToken(ctx context.Context, opts azcore. return tk, nil } -// AuthenticationPolicy implements the azcore.Credential interface on ClientCertificateCredential. -func (c *ClientCertificateCredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +// NewAuthenticationPolicy implements the azcore.Credential interface on ClientCertificateCredential. +func (c *ClientCertificateCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c, options) } + +var _ azcore.TokenCredential = (*ClientCertificateCredential)(nil) diff --git a/sdk/azidentity/client_certificate_credential_test.go b/sdk/azidentity/client_certificate_credential_test.go index c8450a9060bb..7cfcb69e69ea 100644 --- a/sdk/azidentity/client_certificate_credential_test.go +++ b/sdk/azidentity/client_certificate_credential_test.go @@ -44,7 +44,7 @@ func TestClientCertificateCredential_CreateAuthRequestSuccess(t *testing.T) { if err != nil { t.Fatalf("Unexpectedly received an error: %v", err) } - if req.Request.Header.Get(azcore.HeaderContentType) != azcore.HeaderURLEncoded { + if req.Request.Header.Get(headerContentType) != headerURLEncoded { t.Fatalf("Unexpected value for Content-Type header") } body, err := ioutil.ReadAll(req.Request.Body) @@ -90,7 +90,7 @@ func TestClientCertificateCredential_CreateAuthRequestSuccess_withCertificateCha if err != nil { t.Fatalf("Unexpectedly received an error: %v", err) } - if req.Request.Header.Get(azcore.HeaderContentType) != azcore.HeaderURLEncoded { + if req.Request.Header.Get(headerContentType) != headerURLEncoded { t.Fatalf("Unexpected value for Content-Type header") } if len(cred.cert.publicCertificates) != 1 { diff --git a/sdk/azidentity/client_secret_credential.go b/sdk/azidentity/client_secret_credential.go index 6cc0770e3465..0e86db8682d7 100644 --- a/sdk/azidentity/client_secret_credential.go +++ b/sdk/azidentity/client_secret_credential.go @@ -73,9 +73,9 @@ func (c *ClientSecretCredential) GetToken(ctx context.Context, opts azcore.Token return tk, nil } -// AuthenticationPolicy implements the azcore.Credential interface on ClientSecretCredential and calls the Bearer Token policy +// NewAuthenticationPolicy implements the azcore.Credential interface on ClientSecretCredential and calls the Bearer Token policy // to get the bearer token. -func (c *ClientSecretCredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +func (c *ClientSecretCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c, options) } diff --git a/sdk/azidentity/client_secret_credential_test.go b/sdk/azidentity/client_secret_credential_test.go index 80693fc6c45a..e8aec205d5c6 100644 --- a/sdk/azidentity/client_secret_credential_test.go +++ b/sdk/azidentity/client_secret_credential_test.go @@ -49,7 +49,7 @@ func TestClientSecretCredential_CreateAuthRequestSuccess(t *testing.T) { if err != nil { t.Fatalf("Unexpectedly received an error: %v", err) } - if req.Request.Header.Get(azcore.HeaderContentType) != azcore.HeaderURLEncoded { + if req.Request.Header.Get(headerContentType) != headerURLEncoded { t.Fatalf("Unexpected value for Content-Type header") } body, err := ioutil.ReadAll(req.Request.Body) diff --git a/sdk/azidentity/device_code_credential.go b/sdk/azidentity/device_code_credential.go index 55b716622388..d2e28ba956c1 100644 --- a/sdk/azidentity/device_code_credential.go +++ b/sdk/azidentity/device_code_credential.go @@ -80,7 +80,7 @@ type DeviceCodeCredential struct { tenantID string // Gets the Azure Active Directory tenant (directory) ID of the service principal clientID string // Gets the client (application) ID of the service principal userPrompt func(DeviceCodeMessage) // Sends the user a message with a verification URL and device code to sign in to the login server - refreshToken string // Gets the refresh token sent from the service and will be used to retreive new access tokens after the initial request for a token. Thread safety for updates is handled in the AuthenticationPolicy since only one goroutine will be updating at a time + refreshToken string // Gets the refresh token sent from the service and will be used to retreive new access tokens after the initial request for a token. Thread safety for updates is handled in the NewAuthenticationPolicy since only one goroutine will be updating at a time } // NewDeviceCodeCredential constructs a new DeviceCodeCredential used to authenticate against Azure Active Directory with a device code. @@ -167,8 +167,8 @@ func (c *DeviceCodeCredential) GetToken(ctx context.Context, opts azcore.TokenRe } } -// AuthenticationPolicy implements the azcore.Credential interface on DeviceCodeCredential. -func (c *DeviceCodeCredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +// NewAuthenticationPolicy implements the azcore.Credential interface on DeviceCodeCredential. +func (c *DeviceCodeCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c, options) } diff --git a/sdk/azidentity/device_code_credential_test.go b/sdk/azidentity/device_code_credential_test.go index 199f050ecfae..138aebd96ba9 100644 --- a/sdk/azidentity/device_code_credential_test.go +++ b/sdk/azidentity/device_code_credential_test.go @@ -48,7 +48,7 @@ func TestDeviceCodeCredential_CreateAuthRequestSuccess(t *testing.T) { if err != nil { t.Fatalf("Unexpectedly received an error: %v", err) } - if req.Request.Header.Get(azcore.HeaderContentType) != azcore.HeaderURLEncoded { + if req.Request.Header.Get(headerContentType) != headerURLEncoded { t.Fatalf("Unexpected value for Content-Type header") } body, err := ioutil.ReadAll(req.Request.Body) @@ -91,7 +91,7 @@ func TestDeviceCodeCredential_CreateAuthRequestCustomClientID(t *testing.T) { if err != nil { t.Fatalf("Unexpectedly received an error: %v", err) } - if req.Request.Header.Get(azcore.HeaderContentType) != azcore.HeaderURLEncoded { + if req.Request.Header.Get(headerContentType) != headerURLEncoded { t.Fatalf("Unexpected value for Content-Type header") } body, err := ioutil.ReadAll(req.Request.Body) @@ -138,7 +138,7 @@ func TestDeviceCodeCredential_RequestNewDeviceCodeCustomTenantIDClientID(t *test if err != nil { t.Fatalf("Unexpectedly received an error: %v", err) } - if req.Request.Header.Get(azcore.HeaderContentType) != azcore.HeaderURLEncoded { + if req.Request.Header.Get(headerContentType) != headerURLEncoded { t.Fatalf("Unexpected value for Content-Type header") } body, err := ioutil.ReadAll(req.Request.Body) diff --git a/sdk/azidentity/environment_credential.go b/sdk/azidentity/environment_credential.go index 811277bd5056..209d8b407d16 100644 --- a/sdk/azidentity/environment_credential.go +++ b/sdk/azidentity/environment_credential.go @@ -99,8 +99,8 @@ func (c *EnvironmentCredential) GetToken(ctx context.Context, opts azcore.TokenR return c.cred.GetToken(ctx, opts) } -// AuthenticationPolicy implements the azcore.Credential interface on EnvironmentCredential. -func (c *EnvironmentCredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +// NewAuthenticationPolicy implements the azcore.Credential interface on EnvironmentCredential. +func (c *EnvironmentCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c.cred, options) } diff --git a/sdk/azidentity/go.mod b/sdk/azidentity/go.mod index a6920148f51e..6bb6edf06d6e 100644 --- a/sdk/azidentity/go.mod +++ b/sdk/azidentity/go.mod @@ -3,8 +3,8 @@ module github.com/Azure/azure-sdk-for-go/sdk/azidentity go 1.14 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v0.14.0 - github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.17.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1 github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 golang.org/x/net v0.0.0-20201110031124-69a78807bb2b diff --git a/sdk/azidentity/go.sum b/sdk/azidentity/go.sum index 0464250adcd3..1c7384c4ceb1 100644 --- a/sdk/azidentity/go.sum +++ b/sdk/azidentity/go.sum @@ -1,7 +1,7 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.14.0 h1:4HBTI/9UDZN7tsXyB5TYP3xCv5xVHIUTbvHHH2HFxQY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.14.0/go.mod h1:pElNP+u99BvCZD+0jOlhI9OC/NB2IDTOTGZOZH0Qhq8= -github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.0 h1:HG1ggl8L3ZkV/Ydanf7lKr5kkhhPGCpWdnr1J6v7cO4= -github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.0/go.mod h1:k4KbFSunV/+0hOHL1vyFaPsiYQ1Vmvy1TBpmtvCDLZM= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.17.0 h1:j9ra6YGWu3TqNmCprpWYFCqQ3aizqujxrqhI7KLu6qg= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.17.0/go.mod h1:MVdrcUC4Hup35qHym3VdzoW+NBgBxrta9Vei97jRtM8= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1 h1:vx8McI56N5oLSQu8xa+xdiE0fjQq8W8Zt49vHP8Rygw= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1/go.mod h1:k4KbFSunV/+0hOHL1vyFaPsiYQ1Vmvy1TBpmtvCDLZM= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/sdk/azidentity/interactive_browser_credential.go b/sdk/azidentity/interactive_browser_credential.go index a72d83b396e1..8a12ff4aa35c 100644 --- a/sdk/azidentity/interactive_browser_credential.go +++ b/sdk/azidentity/interactive_browser_credential.go @@ -102,8 +102,8 @@ func (c *InteractiveBrowserCredential) GetToken(ctx context.Context, opts azcore return tk, nil } -// AuthenticationPolicy implements the azcore.Credential interface on InteractiveBrowserCredential. -func (c *InteractiveBrowserCredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +// NewAuthenticationPolicy implements the azcore.Credential interface on InteractiveBrowserCredential. +func (c *InteractiveBrowserCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c, options) } diff --git a/sdk/azidentity/managed_identity_client.go b/sdk/azidentity/managed_identity_client.go index 9947dd48d849..2465f73234bc 100644 --- a/sdk/azidentity/managed_identity_client.go +++ b/sdk/azidentity/managed_identity_client.go @@ -181,7 +181,7 @@ func (c *managedIdentityClient) createIMDSAuthRequest(ctx context.Context, id st if err != nil { return nil, err } - request.Header.Set(azcore.HeaderMetadata, "true") + request.Header.Set(headerMetadata, "true") q := request.URL.Query() q.Add("api-version", c.imdsAPIVersion) q.Add("resource", strings.Join(scopes, " ")) @@ -248,7 +248,7 @@ func (c *managedIdentityClient) getAzureArcSecretKey(ctx context.Context, resour if err != nil { return "", err } - request.Header.Set(azcore.HeaderMetadata, "true") + request.Header.Set(headerMetadata, "true") q := request.URL.Query() q.Add("api-version", azureArcAPIVersion) q.Add("resource", strings.Join(resources, " ")) @@ -284,8 +284,8 @@ func (c *managedIdentityClient) createAzureArcAuthRequest(ctx context.Context, k if err != nil { return nil, err } - request.Header.Set(azcore.HeaderMetadata, "true") - request.Header.Set(azcore.HeaderAuthorization, fmt.Sprintf("Basic %s", key)) + request.Header.Set(headerMetadata, "true") + request.Header.Set(headerAuthorization, fmt.Sprintf("Basic %s", key)) q := request.URL.Query() q.Add("api-version", azureArcAPIVersion) q.Add("resource", strings.Join(resources, " ")) @@ -298,7 +298,7 @@ func (c *managedIdentityClient) createCloudShellAuthRequest(ctx context.Context, if err != nil { return nil, err } - request.Header.Set(azcore.HeaderMetadata, "true") + request.Header.Set(headerMetadata, "true") data := url.Values{} data.Set("resource", strings.Join(scopes, " ")) if clientID != "" { @@ -306,7 +306,7 @@ func (c *managedIdentityClient) createCloudShellAuthRequest(ctx context.Context, } dataEncoded := data.Encode() body := azcore.NopCloser(strings.NewReader(dataEncoded)) - if err := request.SetBody(body, azcore.HeaderURLEncoded); err != nil { + if err := request.SetBody(body, headerURLEncoded); err != nil { return nil, err } return request, nil diff --git a/sdk/azidentity/managed_identity_client_test.go b/sdk/azidentity/managed_identity_client_test.go index 70758b3b7b23..7b8952533f15 100644 --- a/sdk/azidentity/managed_identity_client_test.go +++ b/sdk/azidentity/managed_identity_client_test.go @@ -40,7 +40,7 @@ func TestMSITelemetryDefaultUserAgent(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Fatalf("unexpected status code: %d", resp.StatusCode) } - if ua := resp.Request.Header.Get(azcore.HeaderUserAgent); !strings.HasPrefix(ua, UserAgent) { + if ua := resp.Request.Header.Get(headerUserAgent); !strings.HasPrefix(ua, UserAgent) { t.Fatalf("unexpected User-Agent %s", ua) } } @@ -66,7 +66,7 @@ func TestMSITelemetryCustom(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Fatalf("unexpected status code: %d", resp.StatusCode) } - if ua := resp.Request.Header.Get(azcore.HeaderUserAgent); !strings.HasPrefix(ua, customTelemetry+" "+UserAgent) { + if ua := resp.Request.Header.Get(headerUserAgent); !strings.HasPrefix(ua, customTelemetry+" "+UserAgent) { t.Fatalf("unexpected User-Agent %s", ua) } } diff --git a/sdk/azidentity/managed_identity_credential.go b/sdk/azidentity/managed_identity_credential.go index cf64e837ed9c..ba6deab6aa0c 100644 --- a/sdk/azidentity/managed_identity_credential.go +++ b/sdk/azidentity/managed_identity_credential.go @@ -107,8 +107,10 @@ func (c *ManagedIdentityCredential) GetToken(ctx context.Context, opts azcore.To return tk, err } -// AuthenticationPolicy implements the azcore.Credential interface on ManagedIdentityCredential. -// NOTE: The TokenRequestOptions included in AuthenticationPolicyOptions must be a slice of resources in this case and not scopes. -func (c *ManagedIdentityCredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +// NewAuthenticationPolicy implements the azcore.Credential interface on ManagedIdentityCredential. +// NOTE: The TokenRequestOptions included in AuthenticationOptions must be a slice of resources in this case and not scopes. +func (c *ManagedIdentityCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c, options) } + +var _ azcore.TokenCredential = (*ManagedIdentityCredential)(nil) diff --git a/sdk/azidentity/managed_identity_credential_test.go b/sdk/azidentity/managed_identity_credential_test.go index 718b4c95f457..90352f5f6811 100644 --- a/sdk/azidentity/managed_identity_credential_test.go +++ b/sdk/azidentity/managed_identity_credential_test.go @@ -440,7 +440,7 @@ func TestManagedIdentityCredential_CreateIMDSAuthRequest(t *testing.T) { if err != nil { t.Fatal(err) } - if req.Request.Header.Get(azcore.HeaderMetadata) != "true" { + if req.Request.Header.Get(headerMetadata) != "true" { t.Fatalf("Unexpected value for Content-Type header") } reqQueryParams, err := url.ParseQuery(req.URL.RawQuery) diff --git a/sdk/azidentity/username_password_credential.go b/sdk/azidentity/username_password_credential.go index c77d96833b20..049a78248c92 100644 --- a/sdk/azidentity/username_password_credential.go +++ b/sdk/azidentity/username_password_credential.go @@ -77,7 +77,9 @@ func (c *UsernamePasswordCredential) GetToken(ctx context.Context, opts azcore.T return tk, err } -// AuthenticationPolicy implements the azcore.Credential interface on UsernamePasswordCredential. -func (c *UsernamePasswordCredential) AuthenticationPolicy(options azcore.AuthenticationPolicyOptions) azcore.Policy { +// NewAuthenticationPolicy implements the azcore.Credential interface on UsernamePasswordCredential. +func (c *UsernamePasswordCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { return newBearerTokenPolicy(c, options) } + +var _ azcore.TokenCredential = (*UsernamePasswordCredential)(nil) diff --git a/sdk/azidentity/username_password_credential_test.go b/sdk/azidentity/username_password_credential_test.go index 62eab9374ec4..454f579ed59b 100644 --- a/sdk/azidentity/username_password_credential_test.go +++ b/sdk/azidentity/username_password_credential_test.go @@ -38,7 +38,7 @@ func TestUsernamePasswordCredential_CreateAuthRequestSuccess(t *testing.T) { if err != nil { t.Fatalf("Unexpectedly received an error: %v", err) } - if req.Request.Header.Get(azcore.HeaderContentType) != azcore.HeaderURLEncoded { + if req.Request.Header.Get(headerContentType) != headerURLEncoded { t.Fatalf("Unexpected value for Content-Type header") } body, err := ioutil.ReadAll(req.Request.Body)