From f084de6997503859ff24c192b74e0bcf8dd28bfb Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sun, 20 Oct 2019 21:11:25 +0200 Subject: [PATCH 1/3] authentication: using a custom refresh function for Azure CLI Authentication fixes #22 --- authentication/auth_method_azure_cli_token.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/authentication/auth_method_azure_cli_token.go b/authentication/auth_method_azure_cli_token.go index c35c1da..8541149 100644 --- a/authentication/auth_method_azure_cli_token.go +++ b/authentication/auth_method_azure_cli_token.go @@ -90,6 +90,21 @@ func (a azureCliTokenAuth) getAuthorizationToken(sender autorest.Sender, oauth * return nil, err } + var refreshFunc adal.TokenRefresh = func(ctx context.Context, resource string) (*adal.Token, error) { + token, err := obtainAuthorizationToken(resource, a.profile.subscriptionId) + if err != nil { + return nil, err + } + + adalToken, err := token.ToADALToken() + if err != nil { + return nil, err + } + + return &adalToken, nil + } + spt.SetCustomRefreshFunc(&refreshFunc) + auth := autorest.NewBearerAuthorizer(spt) return auth, nil } From ed9123e521b741deeb1def473b6c713ad02f69e8 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 30 Oct 2019 06:47:12 +0100 Subject: [PATCH 2/3] dependencies: adding +incompatible to the go sdk --- go.mod | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ecc5738..4554742 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/hashicorp/go-azure-helpers require ( - github.com/Azure/azure-sdk-for-go v32.5.0 + github.com/Azure/azure-sdk-for-go v32.5.0+incompatible github.com/Azure/go-autorest/autorest v0.9.2 github.com/Azure/go-autorest/autorest/adal v0.8.0 github.com/Azure/go-autorest/autorest/azure/cli v0.2.0 @@ -11,3 +11,5 @@ require ( github.com/hashicorp/go-multierror v1.0.0 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 ) + +go 1.13 From 7e16af17ddb303ef003d98cdcbd20ff3003ab8e7 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 30 Oct 2019 06:57:01 +0100 Subject: [PATCH 3/3] dependencies: switching to use github.com/Azure/go-autorest/autorest/adal@master since this dependency isn't yet tagged, we can pull this one from master --- authentication/auth_method_azure_cli_token.go | 2 +- go.mod | 4 ++-- go.sum | 12 ++++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/authentication/auth_method_azure_cli_token.go b/authentication/auth_method_azure_cli_token.go index 8541149..73816d4 100644 --- a/authentication/auth_method_azure_cli_token.go +++ b/authentication/auth_method_azure_cli_token.go @@ -103,7 +103,7 @@ func (a azureCliTokenAuth) getAuthorizationToken(sender autorest.Sender, oauth * return &adalToken, nil } - spt.SetCustomRefreshFunc(&refreshFunc) + spt.SetCustomRefreshFunc(refreshFunc) auth := autorest.NewBearerAuthorizer(spt) return auth, nil diff --git a/go.mod b/go.mod index 4554742..dd56482 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module github.com/hashicorp/go-azure-helpers require ( - github.com/Azure/azure-sdk-for-go v32.5.0+incompatible + github.com/Azure/azure-sdk-for-go v35.0.0+incompatible github.com/Azure/go-autorest/autorest v0.9.2 - github.com/Azure/go-autorest/autorest/adal v0.8.0 + github.com/Azure/go-autorest/autorest/adal v0.8.1-0.20191028180845-3492b2aff503 github.com/Azure/go-autorest/autorest/azure/cli v0.2.0 github.com/Azure/go-autorest/autorest/to v0.3.0 // indirect github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect diff --git a/go.sum b/go.sum index aa22480..0c28fda 100644 --- a/go.sum +++ b/go.sum @@ -1,22 +1,18 @@ -github.com/Azure/azure-sdk-for-go v32.5.0+incompatible h1:Hn/DsObfmw0M7dMGS/c0MlVrJuGFzHzOpBWL89acR68= -github.com/Azure/azure-sdk-for-go v32.5.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/go-autorest v13.3.0+incompatible h1:8Ix0VdeOllBx9jEcZ2Wb1uqWUpE1awmJiaHztwaJCPk= -github.com/Azure/go-autorest v13.3.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= -github.com/Azure/go-autorest/autorest v0.9.0 h1:MRvx8gncNaXJqOoLmhNjUAKh33JJF8LyxPhomEtOsjs= +github.com/Azure/azure-sdk-for-go v35.0.0+incompatible h1:PkmdmQUmeSdQQ5258f4SyCf2Zcz0w67qztEg37cOR7U= +github.com/Azure/azure-sdk-for-go v35.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= github.com/Azure/go-autorest/autorest v0.9.2 h1:6AWuh3uWrsZJcNoCHrCF/+g4aKPCU39kaMO6/qrnK/4= github.com/Azure/go-autorest/autorest v0.9.2/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= -github.com/Azure/go-autorest/autorest/adal v0.5.0 h1:q2gDruN08/guU9vAjuPWff0+QIrpH6ediguzdAzXAUU= github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= github.com/Azure/go-autorest/autorest/adal v0.8.0 h1:CxTzQrySOxDnKpLjFJeZAS5Qrv/qFPkgLjx5bOAi//I= github.com/Azure/go-autorest/autorest/adal v0.8.0/go.mod h1:Z6vX6WXXuyieHAXwMj0S6HY6e6wcHn37qQMBQlvY3lc= +github.com/Azure/go-autorest/autorest/adal v0.8.1-0.20191028180845-3492b2aff503 h1:Hxqlh1uAA8aGpa1dFhDNhll7U/rkWtG8ZItFvRMr7l0= +github.com/Azure/go-autorest/autorest/adal v0.8.1-0.20191028180845-3492b2aff503/go.mod h1:Z6vX6WXXuyieHAXwMj0S6HY6e6wcHn37qQMBQlvY3lc= github.com/Azure/go-autorest/autorest/azure/cli v0.2.0 h1:pSwNMF0qotgehbQNllUWwJ4V3vnrLKOzHrwDLEZK904= github.com/Azure/go-autorest/autorest/azure/cli v0.2.0/go.mod h1:WWTbGPvkAg3I4ms2j2s+Zr5xCGwGqTQh+6M2ZqOczkE= -github.com/Azure/go-autorest/autorest/date v0.1.0 h1:YGrhWfrgtFs84+h0o46rJrlmsZtyZRg470CqAXTZaGM= github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSWlm5Ew6bxipnr/tbM= github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= -github.com/Azure/go-autorest/autorest/mocks v0.1.0 h1:Kx+AUU2Te+A3JIyYn6Dfs+cFgx5XorQKuIXrZGoq/SI= github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.3.0 h1:qJumjCaCudz+OcqE9/XtEPfvtOjOmKaui4EOpFI6zZc=