From 465631324fc5660e70027691f5caa355b97d4e6d Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Mon, 16 Jul 2018 10:02:48 +0200 Subject: [PATCH] Authentication: Refreshing the Service Principal Token before using it (#1544) This fix was originally contributed by @sophos-jeff in #1349 but has been split-out This allows Azure CLI auth to be used to accessing Key Vaults, which fixes #656. --- azurerm/config.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/azurerm/config.go b/azurerm/config.go index ba76277be7a2..0edd85aea259 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -311,6 +311,12 @@ func getAuthorizationToken(c *authentication.Config, oauthConfig *adal.OAuthConf return nil, err } + err = spt.Refresh() + + if err != nil { + return nil, fmt.Errorf("Error refreshing Service Principal Token: %+v", err) + } + auth := autorest.NewBearerAuthorizer(spt) return auth, nil }