Skip to content

Commit

Permalink
Use "organizations" not "common" as the default authority (#1374)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ellismg authored Jan 12, 2023
1 parent 28ddb71 commit 4f95806
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cli/azd/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions cli/azd/pkg/auth/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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...)
Expand Down
2 changes: 1 addition & 1 deletion cli/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.0-beta.1
0.5.0-beta.2

0 comments on commit 4f95806

Please sign in to comment.