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

fix(amazonq): Update initializationOptions extension name #6468

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/amazonq/src/lsp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { registerInlineCompletion } from '../app/inline/completion'
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
import { ConnectionMetadata } from '@aws/language-server-runtimes/protocol'
import { ResourcePaths, Settings, createServerOptions, globals } from 'aws-core-vscode/shared'
import { ResourcePaths, Settings, oidcClientName, createServerOptions, globals } from 'aws-core-vscode/shared'

const localize = nls.loadMessageBundle()

Expand Down Expand Up @@ -48,7 +48,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: oidcClientName(),
version: '0.0.1',
},
clientId: crypto.randomUUID(),
Expand Down
11 changes: 4 additions & 7 deletions packages/core/src/auth/sso/ssoAccessTokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { oidcClientName, isAmazonQ } from '../../shared/extensionUtilities'
import { randomBytes, createHash } from 'crypto'
import { localize } from '../../shared/utilities/vsCodeUtils'
import { randomUUID } from '../../shared/crypto'
Expand Down Expand Up @@ -438,10 +438,9 @@ function getSessionDuration(id: string) {
*/
export class DeviceFlowAuthorization extends SsoAccessTokenProvider {
override async registerClient(): Promise<ClientRegistration> {
const companyName = getIdeProperties().company
return this.oidc.registerClient(
{
clientName: isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode`,
clientName: oidcClientName(),
clientType: clientRegistrationType,
scopes: this.profile.scopes,
},
Expand Down Expand Up @@ -543,11 +542,10 @@ export class DeviceFlowAuthorization extends SsoAccessTokenProvider {
*/
class AuthFlowAuthorization extends SsoAccessTokenProvider {
override async registerClient(): Promise<ClientRegistration> {
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: oidcClientName(),
clientType: clientRegistrationType,
scopes: this.profile.scopes,
grantTypes: [authorizationGrantType, refreshGrantType],
Expand Down Expand Up @@ -653,11 +651,10 @@ class WebAuthorization extends SsoAccessTokenProvider {
private redirectUri = 'http://127.0.0.1:54321/oauth/callback'

override async registerClient(): Promise<ClientRegistration> {
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: oidcClientName(),
clientType: clientRegistrationType,
scopes: this.profile.scopes,
grantTypes: [authorizationGrantType, refreshGrantType],
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/shared/extensionUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ export function productName() {
return isAmazonQ() ? 'Amazon Q' : `${getIdeProperties().company} Toolkit`
}

/** Gets the client name stored in oidc */
Copy link
Contributor

Choose a reason for hiding this comment

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

potentially a dumb question, but what is "oidc"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just stole this from one of the comments in the codebase 😄:

IAM Identity Center OpenID Connect (OIDC) is a web service that enables a client (such as CLI or a native application) to register with IAM Identity Center. The service also enables the client to fetch the user’s access token upon successful authentication and authorization with IAM Identity Center

export const oidcClientName = once(_oidcClientName)
function _oidcClientName() {
const companyName = getIdeProperties().company
return isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode`
}

export const getExtensionId = () => {
return isAmazonQ() ? VSCODE_EXTENSION_ID.amazonq : VSCODE_EXTENSION_ID.awstoolkit
}
Expand Down
Loading