mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 01:25:37 -05:00
Forces device code auth on SAW and fixes a small axios issue (#9756)
* Force device code and fix a device code issue * Trailing comma
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import axios, { AxiosResponse, AxiosRequestConfig } from 'axios';
|
||||
import * as qs from 'qs';
|
||||
import * as url from 'url';
|
||||
|
||||
@@ -234,13 +234,17 @@ export abstract class AzureAuth {
|
||||
return base64string.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); // Need to use base64url encoding
|
||||
}
|
||||
|
||||
protected async makePostRequest(uri: string, postData: { [key: string]: string }) {
|
||||
const config = {
|
||||
protected async makePostRequest(uri: string, postData: { [key: string]: string }, validateStatus = false) {
|
||||
const config: AxiosRequestConfig = {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
};
|
||||
|
||||
if (validateStatus) {
|
||||
config.validateStatus = () => true;
|
||||
}
|
||||
|
||||
return axios.post(uri, qs.stringify(postData), config);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ export class AzureDeviceCode extends AzureAuth {
|
||||
code: info.device_code
|
||||
};
|
||||
|
||||
const postResult = await this.makePostRequest(uri, postData);
|
||||
const postResult = await this.makePostRequest(uri, postData, true);
|
||||
|
||||
const result: DeviceCodeLoginResult = postResult.data;
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ export class AzureAccountProvider implements azdata.AccountProvider {
|
||||
constructor(
|
||||
metadata: AzureAccountProviderMetadata,
|
||||
tokenCache: SimpleTokenCache,
|
||||
context: vscode.ExtensionContext
|
||||
context: vscode.ExtensionContext,
|
||||
private readonly forceDeviceCode: boolean = false
|
||||
) {
|
||||
vscode.workspace.onDidChangeConfiguration((changeEvent) => {
|
||||
const impact = changeEvent.affectsConfiguration(AzureAccountProvider.CONFIGURATION_SECTION);
|
||||
@@ -52,10 +53,10 @@ export class AzureAccountProvider implements azdata.AccountProvider {
|
||||
const codeGrantMethod: boolean = configuration.get('codeGrant');
|
||||
const deviceCodeMethod: boolean = configuration.get('deviceCode');
|
||||
|
||||
if (codeGrantMethod === true) {
|
||||
if (codeGrantMethod === true && !this.forceDeviceCode) {
|
||||
this.authMappings.set(AzureAuthType.AuthCodeGrant, new AzureAuthCodeGrant(metadata, tokenCache, context));
|
||||
}
|
||||
if (deviceCodeMethod === true) {
|
||||
if (deviceCodeMethod === true || this.forceDeviceCode) {
|
||||
this.authMappings.set(AzureAuthType.DeviceCode, new AzureDeviceCode(metadata, tokenCache, context));
|
||||
}
|
||||
}
|
||||
@@ -69,7 +70,7 @@ export class AzureAccountProvider implements azdata.AccountProvider {
|
||||
if (authType) {
|
||||
return this.authMappings.get(authType);
|
||||
} else {
|
||||
return this.authMappings.get(AzureAuthType.AuthCodeGrant);
|
||||
return this.authMappings.values().next().value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,10 @@ export class AzureAccountProviderService implements vscode.Disposable {
|
||||
let tokenCacheKey = `azureTokenCache-${provider.metadata.id}`;
|
||||
let simpleTokenCache = new SimpleTokenCache(tokenCacheKey, this._userStoragePath, noSystemKeychain, this._credentialProvider);
|
||||
await simpleTokenCache.init();
|
||||
let accountProvider = new AzureAccountProvider(provider.metadata as AzureAccountProviderMetadata, simpleTokenCache, this._context);
|
||||
|
||||
const isSaw: boolean = vscode.env.appName.toLowerCase().indexOf('saw') > 0;
|
||||
let accountProvider = new AzureAccountProvider(provider.metadata as AzureAccountProviderMetadata, simpleTokenCache, this._context, isSaw);
|
||||
|
||||
this._accountProviders[provider.metadata.id] = accountProvider;
|
||||
this._accountDisposals[provider.metadata.id] = azdata.accounts.registerAccountProvider(provider.metadata, accountProvider);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user