Skip to content

Commit db8acef

Browse files
Merge master into feature/q-dev-execution
2 parents 25b9431 + 4d7431f commit db8acef

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "fixed device code detection when running auth through tunneled vscode"
4+
}

packages/core/src/auth/sso/ssoAccessTokenProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { getIdeProperties, isAmazonQ, isCloud9 } from '../../shared/extensionUti
3838
import { randomBytes, createHash } from 'crypto'
3939
import { localize } from '../../shared/utilities/vsCodeUtils'
4040
import { randomUUID } from '../../shared/crypto'
41-
import { isRemoteWorkspace, isWebWorkspace } from '../../shared/vscode/env'
41+
import { getExtRuntimeContext } from '../../shared/vscode/env'
4242
import { showInputBox } from '../../shared/ui/inputPrompter'
4343
import { AmazonQPromptSettings, DevSettings, PromptSettings, ToolkitPromptSettings } from '../../shared/settings'
4444
import { onceChanged } from '../../shared/utilities/functionUtils'
@@ -304,10 +304,10 @@ export abstract class SsoAccessTokenProvider {
304304
*
305305
* Since we are unable to serve the final authorization page
306306
*/
307-
return isRemoteWorkspace() || isWebWorkspace()
307+
return getExtRuntimeContext().extensionHost === 'remote'
308308
}
309309
) {
310-
if (DevSettings.instance.get('webAuth', false) && isWebWorkspace()) {
310+
if (DevSettings.instance.get('webAuth', false) && getExtRuntimeContext().extensionHost === 'webworker') {
311311
return new WebAuthorization(profile, cache, oidc, reAuthState)
312312
}
313313
if (useDeviceFlow()) {

packages/core/src/shared/vscode/env.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as os from 'os'
1010
import { getLogger } from '../logger'
1111
import { onceChanged } from '../utilities/functionUtils'
1212
import { ChildProcess } from '../utilities/processUtils'
13-
import { isWeb } from '../extensionGlobals'
13+
import globals, { isWeb } from '../extensionGlobals'
1414

1515
/**
1616
* Returns true if the current build is running on CI (build server).
@@ -138,8 +138,33 @@ export function isWin(): boolean {
138138
return process.platform === 'win32'
139139
}
140140

141-
export function isWebWorkspace(): boolean {
142-
return vscode.env.uiKind === vscode.UIKind.Web
141+
const UIKind = {
142+
[vscode.UIKind.Desktop]: 'desktop',
143+
[vscode.UIKind.Web]: 'web',
144+
} as const
145+
export type ExtensionHostUI = (typeof UIKind)[keyof typeof UIKind]
146+
export type ExtensionHostLocation = 'local' | 'remote' | 'webworker'
147+
148+
/**
149+
* Detects where the ui and the extension host are running
150+
*/
151+
export function getExtRuntimeContext(): {
152+
ui: ExtensionHostUI
153+
extensionHost: ExtensionHostLocation
154+
} {
155+
const extensionHost =
156+
// taken from https://github.com/microsoft/vscode/blob/7c9e4bb23992c63f20cd86bbe7a52a3aa4bed89d/extensions/github-authentication/src/githubServer.ts#L121 to help determine which auth flows
157+
// should be used
158+
typeof navigator === 'undefined'
159+
? globals.context.extension.extensionKind === vscode.ExtensionKind.UI
160+
? 'local'
161+
: 'remote'
162+
: 'webworker'
163+
164+
return {
165+
ui: UIKind[vscode.env.uiKind],
166+
extensionHost,
167+
}
143168
}
144169

145170
export function getCodeCatalystProjectName(): string | undefined {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "fixed device code detection when running auth through tunneled vscode"
4+
}

0 commit comments

Comments
 (0)