From 4f95806a0a8f5cb4187267ca75dcff8be71fd95d Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 12 Jan 2023 12:50:50 -0800 Subject: [PATCH] Use "organizations" not "common" as the default authority (#1374) Organizations supports using both work/school accounts as well as personal accounts. This matches the default that the `az` CLI uses when logging in. Fixes #1366 --- cli/azd/CHANGELOG.md | 6 ++++++ cli/azd/pkg/auth/manager.go | 9 +++++++++ cli/version.txt | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cli/azd/CHANGELOG.md b/cli/azd/CHANGELOG.md index 737dbf178b8..b1a260fd68f 100644 --- a/cli/azd/CHANGELOG.md +++ b/cli/azd/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 0.5.0-beta.2 (2023-01-12) + +### Bugs Fixed + +- [[#1366]](https://github.com/Azure/azure-dev/issues/1366) Login not possible with personal account after upgrade to 0.5.0. + ## 0.5.0-beta.1 (2023-01-11) ### Features Added diff --git a/cli/azd/pkg/auth/manager.go b/cli/azd/pkg/auth/manager.go index a82c393d8d4..c89af077634 100644 --- a/cli/azd/pkg/auth/manager.go +++ b/cli/azd/pkg/auth/manager.go @@ -38,6 +38,11 @@ const cCurrentUserKey = "auth.account.currentUser" // it ourselves. The value should be a string as specified by [strconv.ParseBool]. const cUseAzCliAuthKey = "auth.useAzCliAuth" +// cDefaultAuthority is the default authority to use when a specific tenant is not presented. We use "organizations" to +// allow both work/school accounts and personal accounts (this matches the default authority the `az` CLI uses when logging +// in). +const cDefaultAuthority = "https://login.microsoftonline.com/organizations" + // The scopes to request when acquiring our token during the login flow or when requesting a token to validate if the client // is logged in. var cLoginScopes = []string{azure.ManagementScope} @@ -83,6 +88,7 @@ func NewManager(configManager config.UserConfigManager) (*Manager, error) { options := []public.Option{ public.WithCache(newCache(cacheRoot)), + public.WithAuthority(cDefaultAuthority), } publicClientApp, err := public.New(cAZD_CLIENT_ID, options...) @@ -161,6 +167,9 @@ func (m *Manager) CredentialForCurrentUser( newOptions := make([]public.Option, 0, len(m.publicClientOptions)+1) newOptions = append(newOptions, m.publicClientOptions...) + + // It is important that this option comes after the saved public client options since it will + // override the default authority. newOptions = append(newOptions, public.WithAuthority(newAuthority)) clientWithNewTenant, err := public.New(cAZD_CLIENT_ID, newOptions...) diff --git a/cli/version.txt b/cli/version.txt index d229e09e2b7..5b56215b043 100644 --- a/cli/version.txt +++ b/cli/version.txt @@ -1 +1 @@ -0.5.0-beta.1 +0.5.0-beta.2