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

auth: Add a getSessionWithScopes to AzureAuthentication #1762

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions auth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auth/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microsoft/vscode-azext-azureauth",
"author": "Microsoft Corporation",
"version": "2.4.1",
"version": "2.5.0",
"description": "Azure authentication helpers for Visual Studio Code",
"tags": [
"azure",
Expand Down
9 changes: 8 additions & 1 deletion auth/src/AzureAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ import type * as vscode from 'vscode';
* Represents a means of obtaining authentication data for an Azure subscription.
*/
export interface AzureAuthentication {
/**
* Gets a VS Code authentication session for an Azure subscription.
* Always uses the default scope, `https://management.azure.com/.default/` and respects `microsoft-sovereign-cloud.environment` setting.
*
* @returns A VS Code authentication session or undefined, if none could be obtained.
*/
getSession(): vscode.ProviderResult<vscode.AuthenticationSession>;
/**
* Gets a VS Code authentication session for an Azure subscription.
*
* @param scopes - The scopes for which the authentication is needed.
*
* @returns A VS Code authentication session or undefined, if none could be obtained.
*/
getSession(scopes?: string[]): vscode.ProviderResult<vscode.AuthenticationSession>;
getSessionWithScopes(scopes: string[]): vscode.ProviderResult<vscode.AuthenticationSession>;
}
29 changes: 15 additions & 14 deletions auth/src/AzureDevOpsSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,26 @@ export class AzureDevOpsSubscriptionProvider implements AzureSubscriptionProvide
}

const accessToken = (await this._tokenCredential?.getToken("https://management.azure.com/.default"))?.token || '';
const getSession = () => {
return {
accessToken,
id: this._tokenCredential?.tenantId || '',
account: {
id: this._tokenCredential?.tenantId || '',
label: this._tokenCredential?.tenantId || '',
},
tenantId: this._tokenCredential?.tenantId || '',
scopes: scopes || [],
};
};
return {
client: new armSubs.SubscriptionClient(this._tokenCredential,),
credential: this._tokenCredential,
authentication: {
getSession: (_scopes: string[] | undefined) => {
return {
accessToken,
id: this._tokenCredential?.tenantId || '',
account: {
id: this._tokenCredential?.tenantId || '',
label: this._tokenCredential?.tenantId || '',
},
tenantId: this._tokenCredential?.tenantId || '',
scopes: scopes || [],
};

}
getSession,
getSessionWithScopes: getSession,
}
};
}
}

public onDidSignIn: Event<void> = () => { return new Disposable(() => { /*empty*/ }) };
Expand Down
5 changes: 4 additions & 1 deletion auth/src/VSCodeAzureSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
client: new armSubs.SubscriptionClient(credential, { endpoint }),
credential: credential,
authentication: {
getSession: () => session
getSession: () => session,
getSessionWithScopes: (scopes) => {
return getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true })
},
}
};
}
Expand Down
Loading