mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -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 azdata from 'azdata';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { AxiosResponse, AxiosRequestConfig } from 'axios';
|
||||||
import * as qs from 'qs';
|
import * as qs from 'qs';
|
||||||
import * as url from 'url';
|
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
|
return base64string.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); // Need to use base64url encoding
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async makePostRequest(uri: string, postData: { [key: string]: string }) {
|
protected async makePostRequest(uri: string, postData: { [key: string]: string }, validateStatus = false) {
|
||||||
const config = {
|
const config: AxiosRequestConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (validateStatus) {
|
||||||
|
config.validateStatus = () => true;
|
||||||
|
}
|
||||||
|
|
||||||
return axios.post(uri, qs.stringify(postData), config);
|
return axios.post(uri, qs.stringify(postData), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export class AzureDeviceCode extends AzureAuth {
|
|||||||
code: info.device_code
|
code: info.device_code
|
||||||
};
|
};
|
||||||
|
|
||||||
const postResult = await this.makePostRequest(uri, postData);
|
const postResult = await this.makePostRequest(uri, postData, true);
|
||||||
|
|
||||||
const result: DeviceCodeLoginResult = postResult.data;
|
const result: DeviceCodeLoginResult = postResult.data;
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ export class AzureAccountProvider implements azdata.AccountProvider {
|
|||||||
constructor(
|
constructor(
|
||||||
metadata: AzureAccountProviderMetadata,
|
metadata: AzureAccountProviderMetadata,
|
||||||
tokenCache: SimpleTokenCache,
|
tokenCache: SimpleTokenCache,
|
||||||
context: vscode.ExtensionContext
|
context: vscode.ExtensionContext,
|
||||||
|
private readonly forceDeviceCode: boolean = false
|
||||||
) {
|
) {
|
||||||
vscode.workspace.onDidChangeConfiguration((changeEvent) => {
|
vscode.workspace.onDidChangeConfiguration((changeEvent) => {
|
||||||
const impact = changeEvent.affectsConfiguration(AzureAccountProvider.CONFIGURATION_SECTION);
|
const impact = changeEvent.affectsConfiguration(AzureAccountProvider.CONFIGURATION_SECTION);
|
||||||
@@ -52,10 +53,10 @@ export class AzureAccountProvider implements azdata.AccountProvider {
|
|||||||
const codeGrantMethod: boolean = configuration.get('codeGrant');
|
const codeGrantMethod: boolean = configuration.get('codeGrant');
|
||||||
const deviceCodeMethod: boolean = configuration.get('deviceCode');
|
const deviceCodeMethod: boolean = configuration.get('deviceCode');
|
||||||
|
|
||||||
if (codeGrantMethod === true) {
|
if (codeGrantMethod === true && !this.forceDeviceCode) {
|
||||||
this.authMappings.set(AzureAuthType.AuthCodeGrant, new AzureAuthCodeGrant(metadata, tokenCache, context));
|
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));
|
this.authMappings.set(AzureAuthType.DeviceCode, new AzureDeviceCode(metadata, tokenCache, context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,7 @@ export class AzureAccountProvider implements azdata.AccountProvider {
|
|||||||
if (authType) {
|
if (authType) {
|
||||||
return this.authMappings.get(authType);
|
return this.authMappings.get(authType);
|
||||||
} else {
|
} 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 tokenCacheKey = `azureTokenCache-${provider.metadata.id}`;
|
||||||
let simpleTokenCache = new SimpleTokenCache(tokenCacheKey, this._userStoragePath, noSystemKeychain, this._credentialProvider);
|
let simpleTokenCache = new SimpleTokenCache(tokenCacheKey, this._userStoragePath, noSystemKeychain, this._credentialProvider);
|
||||||
await simpleTokenCache.init();
|
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._accountProviders[provider.metadata.id] = accountProvider;
|
||||||
this._accountDisposals[provider.metadata.id] = azdata.accounts.registerAccountProvider(provider.metadata, accountProvider);
|
this._accountDisposals[provider.metadata.id] = azdata.accounts.registerAccountProvider(provider.metadata, accountProvider);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user