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

Update redirect-uri to localhost #20692

Merged
merged 14 commits into from
Sep 30, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class AzureAuthCodeGrant extends AzureAuth {
response_type: 'code',
response_mode: 'query',
client_id: this.clientId,
redirect_uri: this.redirectUri,
redirect_uri: `${this.redirectUri}:${serverPort}/redirect`,
state,
prompt: 'select_account',
code_challenge_method: 'S256',
Expand All @@ -170,7 +170,7 @@ export class AzureAuthCodeGrant extends AzureAuth {
return {
authCode,
codeVerifier,
redirectUri: this.redirectUri
redirectUri: `${this.redirectUri}:${serverPort}/redirect`
};

}
Expand Down Expand Up @@ -222,6 +222,21 @@ export class AzureAuthCodeGrant extends AzureAuth {
});

return new Promise<string>((resolve, reject) => {
server.on('/redirect', (req, reqUrl, res) => {
const state = reqUrl.query.state as string ?? '';
const split = state.split(',');
if (split.length !== 2) {
res.writeHead(400, { 'content-type': 'text/html' });
res.write(localize('azureAuth.stateError', 'Authentication failed due to a state mismatch, please close ADS and try again.'));
res.end();
reject(new Error('State mismatch'));
return;
}
const port = split[0];
res.writeHead(302, { Location: `http://127.0.0.1:${port}/callback${reqUrl.search}` });
res.end();
});

server.on('/callback', (req, reqUrl, res) => {
const state = reqUrl.query.state as string ?? '';
const code = reqUrl.query.code as string ?? '';
Expand Down
10 changes: 5 additions & 5 deletions extensions/azurecore/src/account-provider/providerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const publicAzureSettings: ProviderSettings = {
endpoint: 'https://analysis.windows.net/powerbi/api',
azureResourceId: AzureResource.PowerBi
},
redirectUri: 'https://vscode-redirect.azurewebsites.net/',
redirectUri: 'http://localhost',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per https://learn.microsoft.com/en-us/azure/active-directory/develop/reply-url#localhost-exceptions we should be using 127.0.0.1 instead of localhost - although they also mention you have to do some wonky configuration to do that which seems odd...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that too, but I think we'll just use localhost for now, that's also what SSMS is doing

scopes: [
'openid', 'email', 'profile', 'offline_access',
'https://management.azure.com/user_impersonation',
Expand Down Expand Up @@ -158,7 +158,7 @@ const usGovAzureSettings: ProviderSettings = {
endpoint: 'https://analysis.windows.net/powerbi/api',
azureResourceId: AzureResource.PowerBi
},
redirectUri: 'https://vscode-redirect.azurewebsites.net/',
redirectUri: 'http://localhost',
scopes: [
'openid', 'email', 'profile', 'offline_access',
'https://management.usgovcloudapi.net/user_impersonation'
Expand Down Expand Up @@ -217,7 +217,7 @@ const usNatAzureSettings: ProviderSettings = {
endpointSuffix: '.core.eaglex.ic.gov',
azureResourceId: AzureResource.AzureStorage
},
redirectUri: 'https://vscode-redirect.azurewebsites.net/',
redirectUri: 'http://localhost',
scopes: [
'openid', 'email', 'profile', 'offline_access',
'https://management.core.eaglex.ic.gov/user_impersonation'
Expand Down Expand Up @@ -267,7 +267,7 @@ const germanyAzureSettings: ProviderSettings = {
endpoint: 'https://analysis.windows.net/powerbi/api',
azureResourceId: AzureResource.PowerBi
},
redirectUri: 'https://vscode-redirect.azurewebsites.net/',
redirectUri: 'http://localhost',
scopes: [
'openid', 'email', 'profile', 'offline_access',
'https://management.microsoftazure.de/user_impersonation'
Expand Down Expand Up @@ -331,7 +331,7 @@ const chinaAzureSettings: ProviderSettings = {
endpoint: 'https://analysis.windows.net/powerbi/api',
azureResourceId: AzureResource.PowerBi
},
redirectUri: 'https://vscode-redirect.azurewebsites.net/',
redirectUri: 'http://localhost',
scopes: [
'openid', 'email', 'profile', 'offline_access',
'https://management.chinacloudapi.cn/user_impersonation'
Expand Down
2 changes: 1 addition & 1 deletion extensions/microsoft-authentication/src/AADHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { MicrosoftAuthenticationSession } from './microsoft-authentication';

const localize = nls.loadMessageBundle();

const redirectUrl = 'https://vscode-redirect.azurewebsites.net/';
const redirectUrl = 'http://localhost/redirect';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this even used anywhere? Since we use our own custom account handler I didn't think there was anywhere in the app users could actually sign in to their Microsoft account.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is used anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a SQL CARBON EDIT. But if it's not used anywhere I would suggest just reverting it - the fewer changes we make to VS Code stuff the easier merges are.

const loginEndpointUrl = 'https://login.microsoftonline.com/';
const clientId = 'aebc6443-996d-45c2-90f0-388ff96faa56';
const tenant = 'organizations';
Expand Down