Skip to content

Commit

Permalink
Implement Microsoft Auth provider (#69)
Browse files Browse the repository at this point in the history
* Implement Microsoft Auth provider

* Remove comments

---------

Co-authored-by: JuanBravo <[email protected]>
  • Loading branch information
Igsu-Bravo and JuanBravo authored Nov 20, 2023
1 parent 2d2ca65 commit f4ed0d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/authentication/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export interface IHostConfiguration {
token: string | undefined;
}

export const AuthenticationScopes = ['499b84ac-1321-427f-aa17-267ca6975798/.default', 'offline_access'];

export const AuthenticationOptions: vscode.AuthenticationGetSessionOptions = {
createIfNone: true,
};

let USE_TEST_SERVER = false;

export const HostHelper = class {
Expand Down
13 changes: 6 additions & 7 deletions src/azdo/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as azdev from 'azure-devops-node-api';
import { IRequestHandler } from 'azure-devops-node-api/interfaces/common/VsoBaseInterfaces';
import { Identity } from 'azure-devops-node-api/interfaces/IdentitiesInterfaces';
import * as vscode from 'vscode';
import { AuthenticationOptions, AuthenticationScopes } from '../authentication/configuration';
import Logger from '../common/logger';
import { ITelemetry } from '../common/telemetry';
import { SETTINGS_NAMESPACE } from '../constants';
Expand Down Expand Up @@ -73,13 +74,11 @@ export class CredentialStore implements vscode.Disposable {
private async requestPersonalAccessToken(): Promise<string | undefined> {
// Based on https://github.com/microsoft/azure-repos-vscode/blob/6bc90f0853086623486d0e527e9fe5a577370e9b/src/team-extension.ts#L74

Logger.debug(`Manual personal access token option chosen.`, CREDENTIALS_COMPONENT_ID);
const token = await vscode.window.showInputBox({
value: '',
prompt: 'Please provide PAT',
placeHolder: '',
password: true,
});
const session = await vscode.authentication.getSession('microsoft', AuthenticationScopes, AuthenticationOptions);
const token = session.accessToken;

vscode.window.showInformationMessage('Successfully authorized extension in DevOps');

if (token) {
this._telemetry.sendTelemetryEvent('auth.manual');
}
Expand Down

0 comments on commit f4ed0d6

Please sign in to comment.