Skip to content
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

Restore logic for default scope if not provided in getAccessToken function #16

Merged
merged 9 commits into from
Feb 13, 2024
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- `get-access-token` - This command will print an access token to stdout. Other tools can integrate this for getting ADO credentials, for eg, authenticating to ADO Artifact Feeds (NPM, Nuget).
- This extension is not recommended to be installed by itself. You should instead use the [external-repository](https://github.com/microsoft/codespace-features/tree/main/src/external-repository) and [artifacts-helper](https://github.com/microsoft/codespace-features/tree/main/src/artifacts-helper) devcontainer features which will ensure this extension is preinstalled on your Codespace with proper configuration.

### New in versione 1.2
### New in version 1.2
- Add the `adoCodespacesAuth.tenantID` setting

### New in version 1.1
Expand Down
18 changes: 8 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ const statusBarItem = vscode.window.createStatusBarItem(
);

const getAccessToken = async (
scopes: readonly string[]
scopes = [DEFAULT_ADO_SCOPE]
) => {
const tenantID = vscode.workspace.getConfiguration("adoCodespacesAuth").get('tenantID');
if (tenantID && tenantID !== '') {
scopes.push(`VSCODE_TENANT:${tenantID}`);
}

let session = await vscode.authentication.getSession("microsoft", scopes, {
silent: true,
});
Expand Down Expand Up @@ -111,14 +116,7 @@ const createHelperExecutable = (

const authenticateAdo = async (context: vscode.ExtensionContext) => {
try {
const scopes = [DEFAULT_ADO_SCOPE];

const tenantID = vscode.workspace.getConfiguration("adoCodespacesAuth").get('tenantID');
if (tenantID && tenantID !== '') {
scopes.push(`VSCODE_TENANT:${tenantID}`);
}

await getAccessToken(scopes);
await getAccessToken();

createHelperExecutable(context, "ado-auth-helper");
createHelperExecutable(context, "azure-auth-helper");
Expand Down Expand Up @@ -193,4 +191,4 @@ export async function activate(context: vscode.ExtensionContext) {
export function deactivate() {
outputChannel.dispose();
ipc.server.stop();
}
}
Loading