Skip to content

Commit 6c84a77

Browse files
authored
Provide a way to choose a different tenant when authenticating (#609)
* Sign in with the default tenant, but provide a setting to use a different tenant * Don't do work just to ignore it
1 parent cf46ae4 commit 6c84a77

File tree

6 files changed

+136
-140
lines changed

6 files changed

+136
-140
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ You probably have custom tasks installed in your organization.
2727

2828
To provide the most relevant IntelliSense, the extension will automatically detect and use your organization's schema! All you need to do is follow the instructions when prompted.
2929

30-
> If automatic fetching of the organization schema doesn't work, try signing out and signing back in using the `Azure: Sign Out` and `Azure: Sign In` commands from the VS Code command palette (Ctrl/Cmd + Shift + P).
30+
### Using a different Microsoft Entra tenant
31+
32+
The extension uses your account's default tenant to connect to Azure DevOps.
33+
Sometimes, this is not what you want as your Azure DevOps organization is linked to a different tenant.
34+
35+
To get the extension to use the correct tenant, go to the [Tenant](vscode://settings/azure-pipelines.tenant) setting and enter the Microsoft Entra tenant ID that your organization uses.
36+
You can view which tenant your organization is connected to by going to `https://dev.azure.com/YOUR-ORG-HERE/_settings/organizationAad`.
3137

3238
### Specific schema
3339

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@
8787
"type": "string",
8888
"description": "Use a different schema file",
8989
"scope": "machine-overridable"
90+
},
91+
"azure-pipelines.tenant": {
92+
"type": "string",
93+
"description": "Microsoft Entra tenant ID to use when connecting to Azure DevOps. Leave empty to use your account's default tenant.",
94+
"pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$|^$",
95+
"patternErrorMessage": "The tenant must be a valid GUID.",
96+
"scope": "resource"
9097
}
9198
}
9299
},

src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async function activateYmlContributor(context: vscode.ExtensionContext) {
6666

6767
// Let the server know of any schema changes.
6868
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async event => {
69-
if (event.affectsConfiguration('azure-pipelines.customSchemaFile') || event.affectsConfiguration('azure-pipelines.1ESPipelineTemplatesSchemaFile')) {
69+
if (event.affectsConfiguration('azure-pipelines.customSchemaFile') ||
70+
event.affectsConfiguration('azure-pipelines.1ESPipelineTemplatesSchemaFile') ||
71+
event.affectsConfiguration('azure-pipelines.tenant')) {
7072
await loadSchema(context, client);
7173
}
7274
}));

src/messages.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const selectOrganizationLabel = 'Select organization';
77
export const selectOrganizationPlaceholder = 'Select Azure DevOps organization associated with the %s repository';
88
export const signInLabel = 'Sign In';
99
export const signInWithADifferentAccountLabel = 'Sign in with a different account';
10-
export const unableToAccessOrganization = 'Unable to access the "%s" organization. Make sure you\'re signed into the right Microsoft account.';
10+
export const changeTenantLabel = 'Change active tenant';
11+
export const unableToAccessOrganization = 'Unable to access the "%s" organization. Make sure you\'re signed into the right Microsoft account or using the right tenant.';
1112
export const signInForEnhancedIntelliSense = 'Sign in to Microsoft for enhanced Azure Pipelines IntelliSense';
1213
export const userEligibleForEnahanced1ESPTIntellisense = 'Enable 1ESPT Schema in Azure Pipelines Extension settings for enhanced Intellisense';
1314
export const notUsing1ESPTSchemaAsUserNotSignedInMessage = '1ESPT Schema is not used for Intellisense as you are not signed in with a `@microsoft.com` account';

src/schema-association-service-1espt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { URI, Utils } from 'vscode-uri';
88
import * as azdev from 'azure-devops-node-api';
99
import * as logger from './logger';
1010
import * as Messages from './messages';
11-
import { getAzureDevOpsSessions } from './schema-association-service';
11+
import { getAzureDevOpsSession } from './schema-association-service';
1212

1313
const milliseconds24hours = 86400000;
1414

@@ -80,7 +80,7 @@ export async function getCached1ESPTSchema(context: vscode.ExtensionContext, org
8080
void vscode.window.showInformationMessage(Messages.notUsing1ESPTSchemaAsUserNotSignedInMessage, Messages.signInWithADifferentAccountLabel)
8181
.then(async action => {
8282
if (action === Messages.signInWithADifferentAccountLabel) {
83-
await getAzureDevOpsSessions(context, {
83+
await getAzureDevOpsSession(context, {
8484
clearSessionPreference: true,
8585
createIfNone: true,
8686
});

0 commit comments

Comments
 (0)