-
Notifications
You must be signed in to change notification settings - Fork 53
Add manual tenant sign-in fallback for Conditional Access tenants #1511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CoffeeKanzler
wants to merge
10
commits into
microsoft:main
Choose a base branch
from
CoffeeKanzler:issue-1332-azure-tenant-setting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
66a06aa
Add azure tenant setting for sign-in
CoffeeKanzler 451dc18
Use configured tenant for provider authentication
CoffeeKanzler 9567f03
Remove local asset ignore entries
CoffeeKanzler 7d46ce5
Address tenant auth review feedback
CoffeeKanzler 144eebe
Add manual tenant sign-in fallback
CoffeeKanzler 19bcdf8
Persist manual tenant for subscription discovery
CoffeeKanzler 793aa99
Address manual tenant sign-in review feedback
CoffeeKanzler 1cabd47
Potential fix for pull request finding
CoffeeKanzler 2cb8247
Sort tenant picks by label and test empty-discovery fallback
CoffeeKanzler 9cff715
Replace globalState persistence with azure.tenant setting
CoffeeKanzler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as vscode from 'vscode'; | ||
|
|
||
| export const azureTenantSettingKey = 'azure.tenant'; | ||
|
|
||
| export function normalizeConfiguredTenant(tenant: string | undefined): string | undefined { | ||
| const trimmedTenant = tenant?.trim(); | ||
| return trimmedTenant ? trimmedTenant : undefined; | ||
| } | ||
|
|
||
| export function getConfiguredAzureTenant(): string | undefined { | ||
| return normalizeConfiguredTenant(vscode.workspace.getConfiguration().get<string>(azureTenantSettingKey)); | ||
| } | ||
|
|
||
| export function addConfiguredTenantScope(scopes: readonly string[], tenant: string | undefined = getConfiguredAzureTenant()): string[] { | ||
| const normalizedTenant = normalizeConfiguredTenant(tenant); | ||
| if (!normalizedTenant) { | ||
| return [...scopes]; | ||
| } | ||
|
|
||
| return Array.from(new Set([...scopes, `VSCODE_TENANT:${normalizedTenant}`])); | ||
| } | ||
|
|
||
| export function getTenantIdForAuthentication(tenantId: string | undefined, configuredTenant: string | undefined = getConfiguredAzureTenant()): string | undefined { | ||
| return normalizeConfiguredTenant(tenantId) ?? normalizeConfiguredTenant(configuredTenant); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import assert from 'assert'; | ||
| import type { AzureSubscriptionProvider } from '@microsoft/vscode-azext-azureauth'; | ||
| import * as vscode from 'vscode'; | ||
| import { logIn } from '../src/commands/accounts/logIn'; | ||
| import { ext } from '../src/extensionVariables'; | ||
| import { addConfiguredTenantScope, getTenantIdForAuthentication, normalizeConfiguredTenant } from '../src/utils/azureTenantSetting'; | ||
|
|
||
| suite('azureTenantSetting', () => { | ||
| test('normalizeConfiguredTenant returns undefined for blank tenants', () => { | ||
| assert.strictEqual(normalizeConfiguredTenant(undefined), undefined); | ||
| assert.strictEqual(normalizeConfiguredTenant(''), undefined); | ||
| assert.strictEqual(normalizeConfiguredTenant(' '), undefined); | ||
| }); | ||
|
|
||
| test('normalizeConfiguredTenant trims configured tenants', () => { | ||
| assert.strictEqual(normalizeConfiguredTenant(' contoso.onmicrosoft.com '), 'contoso.onmicrosoft.com'); | ||
| }); | ||
|
|
||
| test('addConfiguredTenantScope appends VSCODE_TENANT scope when tenant is configured', () => { | ||
| assert.deepStrictEqual( | ||
| addConfiguredTenantScope(['https://management.azure.com/.default'], 'contoso.onmicrosoft.com'), | ||
| ['https://management.azure.com/.default', 'VSCODE_TENANT:contoso.onmicrosoft.com'] | ||
| ); | ||
| }); | ||
|
|
||
| test('addConfiguredTenantScope leaves scopes unchanged when tenant is not configured', () => { | ||
| assert.deepStrictEqual( | ||
| addConfiguredTenantScope(['https://management.azure.com/.default'], ' '), | ||
| ['https://management.azure.com/.default'] | ||
| ); | ||
| }); | ||
|
|
||
| test('addConfiguredTenantScope does not duplicate tenant scope', () => { | ||
| assert.deepStrictEqual( | ||
| addConfiguredTenantScope( | ||
| ['https://management.azure.com/.default', 'VSCODE_TENANT:contoso.onmicrosoft.com'], | ||
| 'contoso.onmicrosoft.com' | ||
| ), | ||
| ['https://management.azure.com/.default', 'VSCODE_TENANT:contoso.onmicrosoft.com'] | ||
| ); | ||
| }); | ||
|
|
||
| test('getTenantIdForAuthentication prefers explicit tenant over configured tenant', () => { | ||
| assert.strictEqual(getTenantIdForAuthentication('subscription-tenant', 'configured-tenant'), 'subscription-tenant'); | ||
| }); | ||
|
|
||
| test('getTenantIdForAuthentication falls back to configured tenant', () => { | ||
| assert.strictEqual(getTenantIdForAuthentication(undefined, 'configured-tenant'), 'configured-tenant'); | ||
| }); | ||
|
|
||
| test('logIn passes configured azure.tenant to subscription provider signIn', async () => { | ||
| const originalSubscriptionProviderFactory = ext.subscriptionProviderFactory; | ||
| const originalRefreshAzureTree = ext.actions.refreshAzureTree; | ||
| const originalRefreshTenantTree = ext.actions.refreshTenantTree; | ||
| const originalRefreshFocusTree = ext.actions.refreshFocusTree; | ||
|
|
||
| let signedInTenantId: string | undefined; | ||
| const provider = { | ||
| signIn: async (tenant?: { tenantId: string }): Promise<boolean> => { | ||
| signedInTenantId = tenant?.tenantId; | ||
| return true; | ||
| }, | ||
| } as AzureSubscriptionProvider; | ||
|
|
||
| try { | ||
| ext.subscriptionProviderFactory = async () => provider; | ||
| ext.actions.refreshAzureTree = () => { /* no-op */ }; | ||
| ext.actions.refreshTenantTree = () => { /* no-op */ }; | ||
| ext.actions.refreshFocusTree = () => { /* no-op */ }; | ||
|
|
||
| await vscode.workspace.getConfiguration().update('azure.tenant', 'contoso.onmicrosoft.com', vscode.ConfigurationTarget.Global); | ||
|
|
||
| await logIn({} as never); | ||
|
|
||
| assert.strictEqual(signedInTenantId, 'contoso.onmicrosoft.com'); | ||
| } finally { | ||
| await vscode.workspace.getConfiguration().update('azure.tenant', undefined, vscode.ConfigurationTarget.Global); | ||
| ext.subscriptionProviderFactory = originalSubscriptionProviderFactory; | ||
| ext.actions.refreshAzureTree = originalRefreshAzureTree; | ||
| ext.actions.refreshTenantTree = originalRefreshTenantTree; | ||
| ext.actions.refreshFocusTree = originalRefreshFocusTree; | ||
| } | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.