From e72f7461f8cfd17cc7c774a8690c33c655646c5a Mon Sep 17 00:00:00 2001 From: Josh Pinkney Date: Thu, 30 Jan 2025 09:20:24 -0500 Subject: [PATCH] fix(amazonq): Update initializationOptions extension name --- packages/amazonq/src/lsp/client.ts | 3 ++- packages/core/src/auth/sso/ssoAccessTokenProvider.ts | 12 +++++------- packages/core/src/auth/utils.ts | 9 ++++++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/amazonq/src/lsp/client.ts b/packages/amazonq/src/lsp/client.ts index 40965af43ed..2c2e457e335 100644 --- a/packages/amazonq/src/lsp/client.ts +++ b/packages/amazonq/src/lsp/client.ts @@ -12,6 +12,7 @@ import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth' import { AuthUtil } from 'aws-core-vscode/codewhisperer' import { ConnectionMetadata } from '@aws/language-server-runtimes/protocol' import { ResourcePaths, createServerOptions } from 'aws-core-vscode/shared' +import { AuthUtils } from 'aws-core-vscode/auth' const localize = nls.loadMessageBundle() @@ -45,7 +46,7 @@ export async function startLanguageServer(extensionContext: vscode.ExtensionCont name: env.appName, version: version, extension: { - name: `AWS IDE Extensions for VSCode`, // TODO change this to C9/Amazon + name: AuthUtils.clientName(), version: '0.0.1', }, clientId: crypto.randomUUID(), diff --git a/packages/core/src/auth/sso/ssoAccessTokenProvider.ts b/packages/core/src/auth/sso/ssoAccessTokenProvider.ts index d0c8af56c3f..142221cd809 100644 --- a/packages/core/src/auth/sso/ssoAccessTokenProvider.ts +++ b/packages/core/src/auth/sso/ssoAccessTokenProvider.ts @@ -26,7 +26,7 @@ import { AwsLoginWithBrowser, AwsRefreshCredentials, telemetry } from '../../sha import { indent, toBase64URL } from '../../shared/utilities/textUtilities' import { AuthSSOServer } from './server' import { CancellationError, sleep } from '../../shared/utilities/timeoutUtils' -import { getIdeProperties, isAmazonQ, isCloud9 } from '../../shared/extensionUtilities' +import { isAmazonQ } from '../../shared/extensionUtilities' import { randomBytes, createHash } from 'crypto' import { localize } from '../../shared/utilities/vsCodeUtils' import { randomUUID } from '../../shared/crypto' @@ -39,6 +39,7 @@ import { asStringifiedStack } from '../../shared/telemetry/spans' import { showViewLogsMessage } from '../../shared/utilities/messages' import _ from 'lodash' import { builderIdStartUrl } from './constants' +import { clientName } from '../utils' export const authenticationPath = 'sso/authenticated' @@ -451,10 +452,9 @@ function getSessionDuration(id: string) { */ export class DeviceFlowAuthorization extends SsoAccessTokenProvider { override async registerClient(): Promise { - const companyName = getIdeProperties().company return this.oidc.registerClient( { - clientName: isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode`, + clientName: clientName(), clientType: clientRegistrationType, scopes: this.profile.scopes, }, @@ -556,11 +556,10 @@ export class DeviceFlowAuthorization extends SsoAccessTokenProvider { */ class AuthFlowAuthorization extends SsoAccessTokenProvider { override async registerClient(): Promise { - const companyName = getIdeProperties().company return this.oidc.registerClient( { // All AWS extensions (Q, Toolkit) for a given IDE use the same client name. - clientName: isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode`, + clientName: clientName(), clientType: clientRegistrationType, scopes: this.profile.scopes, grantTypes: [authorizationGrantType, refreshGrantType], @@ -666,11 +665,10 @@ class WebAuthorization extends SsoAccessTokenProvider { private redirectUri = 'http://127.0.0.1:54321/oauth/callback' override async registerClient(): Promise { - const companyName = getIdeProperties().company return this.oidc.registerClient( { // All AWS extensions (Q, Toolkit) for a given IDE use the same client name. - clientName: isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode`, + clientName: clientName(), clientType: clientRegistrationType, scopes: this.profile.scopes, grantTypes: [authorizationGrantType, refreshGrantType], diff --git a/packages/core/src/auth/utils.ts b/packages/core/src/auth/utils.ts index dd008a55fb4..da89ce8aba3 100644 --- a/packages/core/src/auth/utils.ts +++ b/packages/core/src/auth/utils.ts @@ -20,7 +20,7 @@ import { TreeNode } from '../shared/treeview/resourceTreeDataProvider' import { createInputBox } from '../shared/ui/inputPrompter' import { CredentialSourceId, telemetry } from '../shared/telemetry/telemetry' import { createCommonButtons, createExitButton, createHelpButton, createRefreshButton } from '../shared/ui/buttons' -import { getIdeProperties, isAmazonQ } from '../shared/extensionUtilities' +import { getIdeProperties, isAmazonQ, isCloud9 } from '../shared/extensionUtilities' import { addScopes, getDependentAuths } from './secondaryAuth' import { DevSettings } from '../shared/settings' import { createRegionPrompter } from '../shared/ui/common/region' @@ -60,6 +60,7 @@ import { EnvVarsCredentialsProvider } from './providers/envVarsCredentialsProvid import { showMessageWithUrl } from '../shared/utilities/messages' import { credentialHelpUrl } from '../shared/constants' import { ExtStartUpSource } from '../shared/telemetry/util' +import { once } from '../shared/utilities/functionUtils' // iam-only excludes Builder ID and IAM Identity Center from the list of valid connections // TODO: Understand if "iam" should include these from the list at all @@ -800,3 +801,9 @@ export async function getAuthType() { } return authType } + +export const clientName = once(_clientName) +function _clientName() { + const companyName = getIdeProperties().company + return isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode` +}